Giter VIP home page Giter VIP logo

hangman2's Introduction

Hangman

Hangman is a fun game to play on a console. This game lets users guess the words and letters with a funny hangman visual. Try and have fun!

cover_image

Features

Existing features

  • Random word pulled from the list of words
  • Visual display of hangman stages
  • Display of how many letters there are in the target word
  • Validating user input and asking the user for a new input if the previous one is invalid

Game flow

The game starts by initiating the code using the main function. Function get_word() retrieves a random word from an imported list of words. After the word has been received, the console introduces the game to the user, displaying a gallows visual and informing the user how many letters are in the target word.

The user enters either a word or a letter. IF a user enters a word, the word is checked if all characters are letters and if the number of letters is equal to the target word. If the conditions are satisfied, the word is compared with the target word. If the condition is not satisfied, user is informed that the input is incorrect and prompted to try to input a value again. When the word meets the If statement, conditions are compared with the target word if the answer is incorrect, the number of tries is reduced by 1. If the comment if correct the progression is updated to the maximal value.

In case the input is a single character, IF statement checks if the input is a letter. If the input is not a letter, user is informed that the input is incorrect and is prompted to try again. If the character is a letter, the letter is assessed if it has been used. If the letter has already been used, the user is informed that the letter has been used and input a different answer. If the letter has not been used yet in the game session, the letter is compared with the letters in the word. If the letter is in the word, the visuals and progression are updated, otherwise the number of tries is reduced by one.

The process keeps repeating itself till the end game conditions have not been met. In this game, there are two end-game conditions. Firs condition is that the progression has achieved its maximum, e.g., the player has guessed the word, or the number of tries has been reduced to 0. If the player fills the progression to maximum, the user is greeted with the message that the game is won. If the player used his last try, he is greeted with the full and final hangman visual and informed that the game is lost and the target word.

After the game has ended, the user is prompted to play another game. If the user answers Y, a new game is started. If the user answers N, the game ends.

flowchart_part1

flowchart_part1

Visuals

In this game, there are used as part of the list. The visuals are pulled based on the number of attempts. As the attempts are reduced, a new image of the hangman is pulled and replaces the previous one on the console. Each visual is designed in a funny way to have an additional funny comment in case the game is played by a younger audience.

Besides the visual display of the hangman, the console also informs the user how many words are in the game to avoid frustration with counting empty spaces.

final_visual

Features to implement

  • add option for user to chosse list of random words base on themes like music, history, movies, pop culture, memes etc.
  • update the code to support multiple word questions
  • implement object oriented programing for easier future work on the code

Testing

I have manually tested this code by doing the following:

  • Passed the code through a PEP8 linter and confirmed there are no problems
  • Tested code in my local terminal
  • I used Python tutor to help me visualise logic in my lines of code
  • I googled validation errors and warnings to better understand how to correct them

use_python_tutor1

use_python_tutor1

Bugs

Solved bugs

  • When I was writing this code, I got bugs as I was mixing the variable answer with the text term guess when writing the code

![use_python_tutor1](documentation/images/bug 3.JPG)

  • I was also getting bugs wile building loops and calling variables out before I assined them

![use_python_tutor1](documentation/images/bug 2.JPG)

  • During the writing and compiling loop inside the loop, I missed a line to update variable for remaining tries, which would give the user an infinite number of guesses with no chance of losing the game and no visual updates

![use_python_tutor1](documentation/images/bug 1.JPG)

  • I had also bugs with wisuals the way they were written. At some point the visuals were distorted. I fixed the bug by adding a dot after \ symbol

Visuals before fixing:

use_python_tutor1

Visuals before fixing in code:

use_python_tutor1

Visuals after fixing the code:

use_python_tutor2

  • I had trouble after the deployment on Heroku to auto deploy my project due to accidently writing in requrements README.structure

Autodeploy fail:

autodeploy_fail

Bugs remaining

  • No bugs remaining

Validator Testing

  • Code has been validated using PEP8
  • run.py, words.py and hangman_visuals.py have been tested
  • Code needed to be fix to pass the validation
  • I read on https://stackoverflow.com/ more details on specific errors and how to fix them
  • No errors were returned after code fixing

Initial validation of run.py:

validation_run_code1

Validation of run.py after fixing:

validation_run_code2

Validation of words.py:

validation_words_code

Initial validation of hangman_visuals.py:

validation_hangman_visuals_code1

Validation of hangman_visuals.py after fixing:

validation_hangman_visuals_code2

Deployment

This project was deployed using Code Institute's mock terminal for Heroku using the following steps:

  • Making sure if there were requirements needed updating before deployment as per Loves-sandwiches walkthrough project
  • Creating a new Heroku app
  • Setting build backs to Python and NodeJS in that order
  • Link the Heroku app to the repository
  • Clicking deploy and enabling auto-deploy

Deploying project:

deploying project

Deployed project:

deploying project

Cedits

  • Code Institute for Python essential template and deployment terminal
  • Kite and Kylie Ying for youtube tutorial on how to build a hangman
  • Stackoverflow for various answer on how to build a code and explanation on errors and warning during code validation
  • Realpython on tips on how to document my code as well as other usefult tips for coding in Python
  • MikhailLenko for the list of words for hangman game
  • Jack my mentor for guidence during this project

hangman2's People

Contributors

voidwulf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.