Project milestone 3 for Code Institute Full-stack development program: Python Terminal.
Hangman is a Python terminal game, which runs in the Code Institute mock terminal on Heroku. The main goal of the game is to guess letters in order to find the word that the computer randomly selects. This project was inspired by the pencil guessing game for two or more players.
According to the site Gambiter, this game has been around since 1894 under the name "Birds, Beasts and Fishes".
-
Game Features
- Logo and Intro Message
- Ask Player Name and City
- Empty Input for Name and City
- Hangman Stage 1
- Hangman Stage 2
- Hangman Stage 3
- Hangman Stage 4
- Hangman Stage 5
- Hangman Stage 6
- Hangman Stage 7
- Hangman Stage 8 - Lose
- Hangman Stage 9 - Win
- Hangman Stage 10 - Win Extra
- Menu Options
- Leaderboard
- Exit Game
- How to Play
-
- PEP 8 Online
- Lighthouse
- Functionality
- [Bugs](Bugs
- As a website creator, I want to:
- Build an easy app for the users to play the game.
- Build a game that is both enjoyable and challenging for the players.
- As a new visitor, I want to:
- Be able to understand the purpose of the App and start a new game.
- Be able to follow the score, see the wrong and right letters appear once I take a turn, and see how many tries remain before the game is over.
- Be able to watch my results and other players' results on the Leaderboard.
- As a returning visitor, I want to:
- Be able to play the game again with a different word as chosen by the computer.
- Be challenged and try to improve on my previous scores.
- Compare my scores with other users on the Leaderboard.
- The colours in the game are supplied by the Python Colorama Model
I spent time planning and thinking about the logic and flow behind the game to ensure I had a general idea of how it could be built. I created flowcharts to assist me with the logical flow throughout the application. The charts were generated using Lucidchart Integration and are shown below.
- When the users reach the website, they will see this feature. The game logo and the intro message are displayed here.
- After the player sees the intro feature, the computer will ask the user's to input their name and city.
- If the player does not input their name and city, this alert will appear.
- After the user inputs their name and city, the program will display the welcome message and the game rules. The player then presses any key to start the game.
This feature displays where the main scene happens. Here the user can play and see the following information about the game:
- Numbers of letters chosen by the computer
- Hangman stages
- Letters guessed right
- Letters guessed wrong
- Current score
- Current number of attempts
- Input to guess a letter or a full word
- Input letters to either guess a letter only or the full word
Any time the player guesses a wrong letter, a part of the hangman appears
- 1 letter guessed wrong, the player will see the hangman and the first part of the hangman: a rope, in green.
- 2 letters guessed wrong the player will see the hangman and 2 parts of the hangman a rope and head in green.
- 3 letters guessed wrong the player will see the hangman and 3 parts of the hangman rope, head and torso in yellow.
- 4 letters guessed wrong the player will see the hangman and 4 parts of the hangman rope, head, torso and the right arm in yellow.
- 5 letters guessed wrong the player will see the hangman and 5 parts of the hangman, rope, head, torso and both arms in red. Also the alert message "Danger Zone" will be displayed.
- 6 letters guessed wrong and the player will see the hangman and 6 parts of the hangman rope, head, torso, both arms and left leg in red. Also the alert message "Danger Zone" will be displayed.
- 7 letters guessed wrong the player will see the full hangman and the game is over.
- If the player guessed the full word letter by letter, they will see this feature and will win the game and get 200 points.
- If the player guessed all the letters that appear in the word thereby completing the word or at least guessing no more than 3 correct letters before completing the full word, this feature will appear.
- In the end of the game users will have access to the menu where they can choose from these options:
[A] - Play Again
[B] - Leaderboard
[C] - Exit Game
- The Leaderboard shows the 15 players with the best scores.
- The players will see this message if they will chose to exit the game by typing [C].
The player has 7 attempts to try to guess the right word by inputting letters or can try to input all the letters to correctly complete the full . The word is randomly chosen by the computer from a list.
- When the game starts the player can see how many letters are in the word [1] and the computer will ask the player to input a letter or a word [7].
- If the player guesses the right letter, they will see a message from the computer [8] the letter guessed displayed in the word length [3], the hangman stage will remain the same [2] and the score will increase by 25 points [5]
- If the player guesses a wrong letter, they will see a message from the computer [9] the letter guessed displayed in the wrong letters guesses [4], the hangman stage will turn to the next stage [2] and the number of attempts will decrease by 1 [6]
- When the player types an invalid input, they will see a message from the computer [10].
- If the user guesses the right word they will see the Winner Feature
- If the player guessed the full word at once or at least no more than 3 letters guessed right before trying to guess the full word, they will win the game-winning 500 extra points and see this feature Winner Feature / Extra Points
- 7 letters guessed wrong and the player will see the Loser Feature
I have used a Google sheet to save the player name, city, score and date. This sheet is connected to the code through the Google Drive and Google Sheet API by the Google Cloud Platform. This method allows me to send and receive data as I had access to the Google Sheet API credentials. I also added in the Config Vars to these credentials when I was deploying the project in Heroku. As this is sensitive data, I had to add the creds.json in the Git ignore file. This would ensure that these credentials are not pushed to the repository.
- Random: returns a random integer to get a random word
- Datetime: returns the full date
- Gspread: allows communication with Google Sheets
- Colorama: allows terminal text to be printed in different colours / styles
- Time: defined time sleep
- google.oauth2.service_accoun: credentials used to validate credentials and grant access to Google service accounts
- Git
- Git was used for version control by utilizing the Gitpod terminal to commit to Git and push to GitHub
- GitHub
- GitHub is used to store the project's code after being pushed from Git
- Heroku
- Heroku was used to deploy the live project
- VSCode
- VSCode was used to create and edit the website
- Lucidchart
- Lucidchart was used to create the flowchart
- PEP8
- The PEP8 was used to validate all the Python code
- Patorjk
- Patorjk (ASCII Art Generator) was used to draw the game logos
The PEP8 Validator Service was used to validate every Python file in the project to ensure there were no syntax errors in the project.
- No errors or warnings were found during the testing of the code in PEP8
Lighthouse was used to test Performance, Best Practices, Accessibility and SEO on the Desktop.
-
Desktop Results:
-
The terminal has no issues and is working properly
-
The typewriter starts typing at the right time and is working correctly
-
The input for name and city have the right behaviour and shows the user an alert if the input is empty
-
The game rules appear without any issues after the player submits their name and city
-
The option to press any key to start a game is running well
-
The game runs without any issues and as expected
-
At the end of the game, the Leaderboard is updating correctly
-
All the menu options are working without any fails
- When I first built the ASCII art for the logo I got the warning "line too long (126 > 79 characters)" from PEP8.
- I had to rebuild the logo using the program Patorjk (ASCII Art Generator) to avoid these issues.
- This site was deployed by completing the following steps:
- Log in to Heroku or create an account
- On the main page click the button labelled New in the top right corner and from the drop-down menu select Create New App
- You must enter a unique app name
- Next select your region
- Click on the Create App button
- The next page is the project’s Deploy Tab. Click on the Settings Tab and scroll down to Config Vars
- Click Reveal Config Vars and enter port into the Key box and 8000 into the Value box and click the Add button
- Click Reveal Config Vars again and enter CREDS into the Key box and the Google credentials into the Value box
- Next, scroll down to the Buildpack section click Add Buildpack select python and click Save Changes
- Repeat step 8 to add node.js. o Note: The Buildpacks must be in the correct order. If not click and drag them to move into the correct order
- Scroll to the top of the page and choose the Deploy tab
- Select Github as the deployment method
- Confirm you want to connect to GitHub
- Search for the repository name and click the connect button
- Scroll to the bottom of the deploy page and select the preferred deployment type
- Click either Enable Automatic Deploys for automatic deployment when you push updates to Github
- Fork this project by following the steps:
- Open GitHub
- Click on the project to be forked
- Find the Fork button at the top right of the page
- Once you click the button the fork will be in your repository
- Clone this project by following the steps:
- Open GitHub
- Click on the project to be cloned
- You will be provided with three options to choose from, HTTPS, SSH, or GitHub CLI, click the clipboard icon in order to copy the URL
- Once you click the button the fork will be in your repository
- Open a new terminal
- Change the current working directory to the location that you want the cloned directory
- Type git clone and paste the URL copied in step 3
- Press Enter and the project is cloned
- All the content in the game is original
- The terminal function and template for the deployable application was provided by Code Institute - Template
- The Python code for the typewriter was taken from the following tutorial: Kwasii
- Special thanks to my mentor Sandeep Aggarwal, my colleagues at Code Institute, Kasia Bogucka, Shellie Downie and Mairéad Gillic for their assistance throughout this project.