Git Product home page Git Product logo

hangman's Introduction

THE HANGMAN GAME

THE HANGMAN GAME is a Command Line Interface program built as the third Milestone Project using Python.

display game


TABLE OF CONTENTS



USER EXPERIENCE


Users are able to play a game where they can try to guess the hidden word or phrase (depending on the difficulty level selected), one letter at a time. The game ends either when the user runs out of lives or when the correct answer was guessed.

FLOWCHART


The flowchart for THE HANGMAN GAME was built using Lucidchart.

The flowchart visualizes the separate steps of the game in sequential order.

Once the program starts running the user is asked for a name input which is then followed by another input where the user has the option of reading the game rules and instructions before playing. The third input will require the user to select a difficulty level which will then start the main game loop with either a word or a phrase to be guessed.

The hidden word or phrase will then be visualized with a series of underlineS '_' and any special characters will be given. Every guess is stored and displayed for the user and the correct guesses will uncover the hidden letters in their correct place(s). Every wrong answer will take away a life and draw a part of the stick man.

The game is over either when the correct answer was guessed or if the user runs out of lives and the hangman is complete. Once the game is over the user will be presented with an option to play again and if they do, this will take them back to the difficulty level selection phase.

flowchart

JUMP to TOP


EXISTING FEATURES


NAME INPUT & GREETING


The user is asked to input a name for the game which is then used to personalize experience with a greeting. The input is checked so that it does not contain any numbers or special characters. An empty string will also throw an 'Invalid input' feedback and the user will be asked to try again.

GAME RULES


The user is prompted to make a choice if they want to see the game rules and instructions before playing. The input is checked so that only the given options are accepted and everything else throws a 'Invalid input' error and the user will be asked to try again.

DIFFICULTY LEVEL SELECTION


At this stage the user is asked to select difficulty level for the game. They will have 2 options to choose from : easy and hard. Depending on their choice the game will build up for guessing either a random word from a list of approximately 2500 words or a random phrase from a list of approximately 200 idioms.

features

GAME BOARD


Once the difficulty level is selected the game board is printed. We first see a banner for the game which helps to set the mood. This is followed by an empty gibbot where the hangman will be drawn and below is the placeholder of the word or phrase to be guessed. For every letter in the word or phrase an underline will be displayed to represent the number of characters the correct answer has. All guesses made by the user (right or wrong) will be stored and displayed to help keep track. Below, the user will have a life count which will show how many attempts are left until the game is over.

easy game hard game

JUMP to TOP


FUTURE IMPROVEMENT IDEAS


  • create a more complex design for the game board and banner
  • expand the list of phrases for the game so it doesn't become repetitive
  • improve the one at a time letter guess to word guesses as well
  • add different options for difficulty level choice (like adding medium level or categories)
  • add function to count wins and losses for user

JUMP to TOP


TECHNOLOGIES USED


  • Python - programming language used to build the game
  • Heroku - platform used to deploy the game
  • Lucidchart - used for creating the flowchart of the programme
  • Github - used for creating and storing the repository of the project
  • Gitpod - used for creating and trialing the code
  • Visual Studio Code - code editor used to create initial version of the project
  • PowerShell - command line program used to test partial code correctness and bug solutions

JUMP to TOP


PYTHON MODULES


  • random - module generates random actions
  • platform - module accesses underlying platform's data
  • os - module interacts with the underlying operating system

TESTING


MANUAL TESTING


THE HANGMAN GAME was tested throughout development in VS Code, PowerShell, Gitpod and Heroku. Manual testing verified and confirmed the functionality of the steps listed below:

  • Program Start

    • program starts without any detected issues
    • name input request runs on start-up
    • invalid input calls error feedback for user
  • Name input

    • input is validated against special characters, numbers and empty spaces
    • invalid input calls error feedback for user
  • Game Rules

    • option to see the game rules runs after name input
    • input is validated to only accept given options
    • invalid input calls error feedback for user
  • Difficulty level selection

    • difficulty selection runs after game rules option
    • input is validated to only accept given options
    • valid input pulls random item from the correct list based on difficulty selection
    • invalid input calls error feedback for user
  • Game board

    • initial empty game board is printed after difficulty selection
  • Letter guess

    • input is validated to only accept letters (A-Z)
    • correct guesses uncover the letters in their respective place(s)
    • invalid input calls error feedback for user
  • Remaining attempts

    • remaining attempts are displayed as lives
    • wrong guess will decrease the number of lives and draw the respective part of the stick man
  • Used letters tracker

    • user guesses are stored and displayed for user
    • guess repetition calls error feedback for user
  • End game

    • the game ends once correct answer is guessed or the man is hung
    • provides winner or looser message feedback for user
  • Play again

    • play again option runs correctly when game is over
    • game returns to difficulty selection and restarts correctly on affirmative
    • otherwise the program stops running while providing a feedback message for user

CODE VALIDATION


All python files pass validation through the PEP8 online check with no errors.

JUMP to TOP


BUGS


While creating the game i have identified and corrected the below bugs:

  • Even though every letter was guessed correctly the word builder would not be equal to the randomly choosen word/phrase as it was a list of strings. The bug solution was tested and proved using PowerShell.
while option in ['Y', 'YES']:
        while error_count != error_limit:
            print_board(build_word, used_letters)
            guess = get_user_input(used_letters)
            if not check_user_input(guess, random_word, build_word):
                error_count += 1
            if str(build_word) == random_word:	    # bug
                winner = True
                break
 while option in ['Y', 'YES']:
        while error_count != error_limit:
            print_board(build_word, used_letters)
            guess = get_user_input(used_letters)
            if not check_user_input(guess, random_word, build_word):
                error_count += 1
            if ''.join(build_word) == random_word:	    # correction
                winner = True
                break

correction trial

  • Letter guess input would accept consecutive letters from abc as ascii_letters is a long string with letters (a-Z). The bug solution was tested and proved using PowerShell.

bug 2

fix 2

  • On new game the board would not reset the gibbot to it's initial empty stage. Converting the two relevant class attributes to lists solved the issue.

bug 3

def __init__(self, random_word, level):
        self.random_word = random_word
        self.hang = list(hang)      # convert to list
        self.hbody = list(hbody)        # convert to list
        self.build_word = []
        self.used_letters = []
        self.error_limit = 11
        self.error_count = 0
        self.winner = False
        self.level = level

JUMP to TOP


DEPLOYMENT


  • Deployment

The project was deployed to Heroku. Deployment steps are:

  1. Log in to Heroku or Set up an account

log in

  1. Create a new app from the dashboard

new app

  1. Enter a unique name and select region
  2. Click the 'Create app' button

create app

  1. Select the settings tab from navigation panel
  2. Click 'Reveal config vars' button
  3. In the 'Key' field input 'PORT'; in the 'Value' field input '8000'
  4. Press 'Add' button
  5. Scroll down and click 'Add buildpack'
  6. First add 'Python'
  7. Then add 'node.js'

settings

  1. Scroll up and select the 'Deploy' tab from navigation menu
  2. In the 'Deployment method' section select GitHub and connect your repository
  3. Scroll down and select your preferred deployment type then click 'Deploy branch'

deploy

  • Cloning the repository

Cloning repository creates a local copy on the computer for the remote GitHub repository.

  1. On GitHub navigate to the main page of the repository
  2. Find and click code in the top right corner
  3. Copy the URL for the repository
  4. Open any command line where git is installed
  5. Change the current working directory to the location of your choice
  6. Type git clone, and then paste copied URL
  7. Press ENTER to create local clone

clone

JUMP to TOP


CREDITS


CONTENT


RECOGNITION


The website was created for Code Institute's Full Stack Software Development Diploma Course as the third Milestone Project.

Therefore, I would like to take this opportunity to show my appreciation and thanks to my mentor Precious Ijege and the whole of Code Institute for all the help and support received throughout the creation of this project.

JUMP to TOP

hangman's People

Contributors

vivhubb avatar

Watchers

 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.