(Developer: Benjamin Draper)
This is a command-line version of the game Hangman, the objective of the game is to guess the word before the number of lives you have run out and your virtual man is hung.
- Project Goals
- User Experience
- User Stories
- Design
- Technologies Used
- Features
- Validation
- Testing
- Bugs
- Deployment
- Credits
- Acknowledgements
- To have a fun and easy game to play.
- To be able to how to play
- To be able to create an account and track the score.
- Create a game that is intuitive to use.
- Ensure the users understand the objective of the game.
- Give the user feedback while they are playing the game.
The Target audience for the game is not specific to any group of individuals, the game can be played by anyone who is looking for an entertaining way to pass some time. It would be best suited to people who are about the age of 10 years old due to the word selection used, younger people might find it quite difficult.
- The user can expect an easy-to-use bug free game.
- The user can expect to find straightforward navigation and guidance.
- The user can expect to see personalised user information when logging into their account and their access to their total score.
- The user can except to see feedback on the game as it runs and the result.
The user is given a short description for how to play the game when you login to your account. Throughout the game you are given guidance to make the game user friendly. You are always shown what letters you have already used and how many lives you have left. When navigating through the menu’s you are given your options or asked to enter a specific input into the terminal to continue with the game.
- I want clear options to select in all the game menus.
- I want to be able to read how to play the game.
- I want to be able to log in to my account.
- I want to be to log back into my account when I return to the game.
- I want to receive feedback throughout the game.
- I want to get feedback when I win the game.
- I want to be able to play multiple games when I'm logged in.
- I want to see how many games I've won so far.
- I want users to have a good experience when they are playing the game.
- I want users to be able to easily select options from all menus throughout the game.
- I want all emails, usernames, and scores to be saved in a Google spreadsheet.
- I want the user to see feedback from the game when they enter the wrong letter in the game.
- I want the user to receive feedback from the game when they enter an invalid answer.
This diagram shows the structure and flow of the game logic within the application.
- Python language for the structure, logic and decision making of the game.
- HTML and CSS used for the small edits made to the template files provided by Code Institute to customize the look of the terminal page.
- Diagrams.net was used to create my flow diagram.
- GitHub is being used as my repository to store all of my code and manage version control.
- Google Cloud Platform was used to store and create the access credentials for the google sheet storing the user information.
- Google Sheets is being used for storing player details.
- Heroku Platform is used to deploy the project to a live environment.
- PEP8 has been used to verify all the code against python coding standards.
- os is used to allow me to clear the terminal for different types of operating systems.
- random is used to randomize the word used within the game, I used a selection of predefined words that it can select randomly select from.
- string is used to ensure that all the characters entered by the player weather they are uppercase, or lowercase are interpreted as a lowercase character to prevent errors.
- sys is used to exit the game cleanly when the player decides to exit.
- unittest – used to carry out automated testing on the validation.py file
- email_validator – JUSTIFICATION: I used this library to make sure the player had entered a valid email address when signing up for an account.
- gspread – JUSTIFICATION: I used gspread to allow access to and edit the data in my google spreadsheet storing the player information
- google.oauth2.service_account – JUSTIFICATION: This is a required part of the Google API to allow access to the game the authorization to access the spreadsheet, during development I used a creds.json file and in Heroku I have saved the contents of this file in the config vars section.
- Asks the player for their email address to login.
- informs them if the email they input is not in the correct format.
- Shows the user their score from previous games they have played.
- User stories covered: 3, 4, 8, 13
- Provides the ability for a user to login or create a new account from their email address.
- Saves the player to a Google Spreadsheet to be recalled when needed.
- User stories covered: 3, 4, 11
- Explains to the user how to play the game and navigate through the menus.
- Is displayed before the user must interact with any menu or the main game.
- User stories covered: 1, 2, 9, 10
- Gives the player clear instructions throughout the game to help them play the game.
- User stories covered: 1, 5, 9, 10
- Takes the user input email address validates against a template
- Asks the user to re-enter the email address if it is incorrect
- If it is valid it passes and allows the user to either log in or create a user
- User stories covered: 1, 3, 5, 9, 13
- This is a message that is displayed before the player has logged into their account
- The message explains how to play the game and asks the player to login
- User stories covered: 1, 2, 3, 4, 9
- Informs the player when they enter an invalid character into a prompt or menu with the game
- Will not allow the user to progress forwards without a correct input
- Asks the user to try their input again
- User stories covered:1, 5, 9, 10, 12, 13
- Displays the title created for the game.
- Displays the numbers of lives remaining for the player.
- Displays the Letters that have already been used within this game.
- Displays the status of the gallows and the man getting hung.
- Displays the status of the word being guessed.
- Displays a warning when an invalid character is entered.
- Tells the player when the enter a letter that is not in the word.
- Provides feedback when the game has been won.
- Gives the option to play again and prints the users total when the next game starts.
- User stories covered: 1, 5, 6, 7, 8, 12, 13
PEP8 Validation Service has been used to check the code for PEP8 requirements, my code passes with no errors and no warnings to show.
The approach I decided to take to test this project was to manually test the user stories myself and get another individual to follow the same actions, using different credentials when logging in to test the game.
After this I decided to use an automated testing library called unittest to test my validation file. This involves building tests to allow the game to step through and test the functions within the validation file that I have targeted.
This section follows the user story structure and will test each user story against its own scenario.
- I want clear options to select in all the game menus.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
How To Play | When the game is opened read the instructions how to play the game | User can read and understand how the game and menus should be navigated | Works as expected |
Game Options | At each prompt the player can read the instructions given to guide them to the correct goal | User can read and understand how to navigate forward | Works as expected |
Email Validation | The user enters a incorrect email address | The game identifies the email is not correct and asks the player to try again before continuing | Works as expected |
Welcome Message | When the game is opened, view the welcome message, and read the instructions how to play the game | User can read and understand how the game and menus should be navigated | Works as expected |
Input Validation | The user enters a incorrect character at a given prompt | The game identifies the character is invalid and asks the player to try again before continuing | Works as expected |
Game | The player enters a valid character into the game | The game either reveals the letter within the word or the player loses a life | Works as expected |
- I want to be able to read how to play the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
How To Play | When the game is opened read the instructions how to play the game | User can read and understand how the game and menus should be navigated | Works as expected |
Welcome Message | When the game is opened, view the welcome message and read the instructions how to play the game | User can read and understand how the game and menus should be navigated | Works as expected |
- I want to be able to log in to my account.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
User Login | On the welcome message screen the player can type in their email address to sign into their account | User signs into their account | Works as expected |
User Sign Up | On the welcome message screen the player can type in their email address and name to sign up for a new account | User signs up for a new account | Works as expected |
Email Validation | On the welcome message screen the player can type in their email address to sign into their account | User signs into their account, the game verifies that the email is correct | Works as expected |
Welcome Message | On the welcome message screen the player can type in their email address to sign into their account | User signs into their account | Works as expected |
- I want to be to log back into my account when I return to the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
User Login | On the welcome message screen the player can type in their email address to sign into their account | User signs back into their account | Works as expected |
User Sign Up | On the welcome message screen the player can type in their email address and name to sign up for a new account | User signs up for a new account | Works as expected |
Welcome Message | On the welcome message screen the player can type in their email address to sign into their account | User signs back into their account | Works as expected |
- I want to receive feedback throughout the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game Options | At the prompt to start a new game the user chooses to start a new game or quit | The User either starts a new game or quit the game | Works as expected |
Email Validation | On the welcome message screen the player can type in their email address to sign into their account | User signs into their account, the game verifies that the email is correct | Works as expected |
Input Validation | The user enters a incorrect character at a given prompt | The game identifies the character is invalid and asks the player to try again before continuing | Works as expected |
Game | The player enters a valid character into the game | The game either reveals the letter within the word or the player loses a life | Works as expected |
- I want to get feedback when I win the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game | The player enters the final character into the game | The game either reveals the word and tells the player they have won the game | Works as expected |
- I want to be able to play multiple games when I'm logged in.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game | The player enters the final character into the game | The game either reveals the word and tells the player they have won the game, displaying a prompt asking if they would like to play again | Works as expected |
- I want to see how many games I've won so far.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
User Login | On the welcome message screen the player can type in their email address to sign into their account | User signs back into their account and is shown the number of games they have previously won | Works as expected |
Game | The player enters the final character into the game | The game either reveals the word and tells the player they have won the game, if the player decides to play again the total score will be displayed at the start | Works as expected |
- I want users to have a good experience when they are playing the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
How To Play | When the game is opened read the instructions how to play the game | User can read and understand how the game and menus should be navigated | Works as expected |
Game Options | At each prompt the player can read the instructions given to guide them to the correct goal | User can read and understand how to navigate forward | Works as expected |
Email Validation | On the welcome message screen the player can type in their email address to sign into their account | User signs into their account, the game verifies that the email is correct, to prevent errors signing back in later | Works as expected |
Welcome Message | On the welcome message screen the player can read a description of the game and sign into their account | User signs back into their account | Works as expected |
Input Validation | The user enters a incorrect character at a given prompt | The game identifies the character is invalid and asks the player to try again before continuing, preventing the user making an error | Works as expected |
- I want users to be able to easily select options from all menus throughout the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
How To Play | When the game is opened read the instructions how to play the game | User can read and understand how the game and menus should be navigated | Works as expected |
Game Options | At each prompt the player can read the instructions given to guide them to the correct goal | User can read and understand how to navigate forward | Works as expected |
Input Validation | The user enters a incorrect character at a given prompt | The game identifies the character is invalid and asks the player to try again before continuing, preventing the user making an error | Works as expected |
- I want all emails, usernames, and scores to be saved in a Google spreadsheet.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
User Sign Up | On the welcome message screen the player can type in their email address and name to sign up for a new account | User signs up for a new account and user email, name and a blank score is store in the Google sheet | Works as expected |
- I want the user to see feedback from the game when they enter the wrong letter in the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Input Validation | The user enters a incorrect character at a given prompt | The game identifies the character is invalid and asks the player to try again before continuing, preventing the user making an error | Works as expected |
Game | The user enters an already used character at a given prompt | The game identifies the character is valid and asks tells player the letter already used before asking to try again | Works as expected |
- I want the user to receive feedback from the game when they enter an invalid answer.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
User Sign up | On the welcome message screen the player can type in their email address and name to sign up for a new account | Player is told the email the email is invalid and they are asked to try again | Works as expected |
Email Validation | On the welcome message screen the player can type in their email address to sign into their account | User signs into their account, the game verifies that the email is correct, to prevent errors signing back in later | Works as expected |
Input Validation | The user enters a incorrect character at a given prompt | The game identifies the character is invalid and asks the player to try again before continuing, preventing the user making an error | Works as expected |
Game | The user enters a valid character at a given prompt | The game identifies the character is valid and asks tells player the letter is not in the word before losing a life and asking to try again | Works as expected |
To perform automated testing I Python's unittest library to write 9 seperate functions to verify the correct operation of the game. Through the use of coverage library was able to easilly view and achieve 93% total coverage of my code with no errors.
My tests were groups together in classes that tested similar functions together.
The 'TestEmail' class has two functions inside, these set to individually test the email validation upon logging in or signing up for an account to make sure the code can check if the email is both correct and respond appropiately or if incorrectly also take appropiate action.
The 'TestLogin' class has one function to test the normal login of an already registered user, it does this by calling the function and using a test user that is stored in the Google sheet with the rest of the users. Due to the nature of the game if allowed to continue it would follow through in to the main game so I re-arranged my words allowing me to add a "quit code" into my game for testing purposes this allows the test to reach the end game as fast as possible while testing small amounts of side code along the way.
The 'TestNewLogin' class performs a similar task to 'TestLogin' however it makes sure the code to sign up a new player by using two functions. One function is to register the player, inputting the email and name then emailing the quit code to close the game and the second is to remove teh user from teh spreasheet for subsequent runs of the test.
The 'TestDisplays' class has 3 functions to test the main elements of the user interface. This class will test the re-printing of the title art each time it is called to make sure it is shown to the user to maintain a pleasing look. It will also check to make sure the ‘clear_log’ function is working correctly so that the user does not have a very cluttered and confusing screen when they are playing the game. Lastly this function will check to make sure the welcome message has been displayed correctly and as this will ask the player to then sign in it immediately calls on the quit code again.
The ‘TestRestartGame’ class has only one function to test the ability to restart the game at the prompt given when the player wither wins or loses, this function tests all three scenarios where the user could enter invalid input, “y” to restart in which case the quit code is used to bring the game back round to then test the final case “n” at which point the game exits and the test is expected to end.
Bug | Fix |
---|---|
Game incorrectly listing the lettersthe player has already used within the game due to incorrect usage of the '.join' function | Splitting the f'string' into two pieces and using the '.join' on the second part |
Game not recognising 'y' or 'n' characters to restart the game upon either winning or losing | Missed a pair of open and closing brackets on line 82 for the '.lower' causing an error |
When the player runs out of lives the game did not end and the player has minus number of lives | changed the 'While' loop to add an extra 'AND' statement to stop game on both the letters in the word and the number of lives |
When the game has been won the next game automatically started and the prompt asking the user weather they wanted to continue was skipped | Add new function to separate the code to restart the game, asking the user weather they want to restart or quit |
Game not displaying gallows dictionary when the game has been lost by the player | Add a print statement checking if the lives are eqaul to 0 to print the full gallows picture |
Game looping round within itself, redirected towards welcome message when asked to quit instead of closing | Changed function call to close the game gracefully |
This application has been deployed from GitHub to Heroku by following the steps:
- Create or log in to your account at heroku.com
- Create a new app, add a unique app name (this project is named "ben-hangman") and choose your region
- Click on create app
- Go to "Settings"
- Under Config Vars store any sensitive data you saved in .json file. Name 'Key' field, copy the .json file and paste it to 'Value' field. Also add a key 'PORT' and value '8000'.
- Add required buildpacks (further dependencies). For this project, I set up 'Python' and 'node.js' in that order.
- Go to "Deploy" and select "GitHub" in "Deployment method"
- To link up our Heroku app to our Github repository code enter your repository name, click 'Search' and then 'Connect' when it shows below
- Choose the branch you want to buid your app from
- If prefered, click on "Enable Automatic Deploys", which keeps the app up to date with your GitHub repository
- Wait for the app to build. Once ready you will see the “App was successfully deployed” message and a 'View' button to take you to your deployed link.
- Go to the GitHub repository
- Click on Fork button in top right corner
- You will then have a copy of the repository in your own GitHub account.
- Go to the GitHub repository
- Locate the Code button above the list of files and click it
- Highlight the "HTTPS" button to clone with HTTPS and copy the link
- Open Git Bash
- Change the current working directory to the one where you want the cloned directory
- Type git clone and paste the URL from the clipboard ($ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY)
- Press Enter to create your local clone
- Flaticon was used for the website favicon.
- FontAwesome was used for the GitHub icon.
- FontAwesome was used for the LinkedIn icon.
- Code Institute’s git template IDE and "Love Sandwiches - Essentials Project" which helped me connect the Google Spreadsheet to my project.
- Pypi was used for a number of python modules and libraries and how to install them.
- gspread docs explained how to obtain values, rows and create new data.
- Aleksandra Haniok’s Connect 4 for introducing me to unittests and enabling me to grasp the concept.
I would like to thank everyone who supported me in the development of this project:
- My mentor Mo Shami, for his feedback, advice, guidance, and support.
- My partner Megan Fox, for her support advice, help testing and allowing me the time to work on my project.
- Code Institute community on Slack for resources and support