When I searched online for inspiration on what to make for my third project I wanted it to be something that most people recognize and understand. I love games myself so I knew that I wanted to make some kind of game. When I finally saw that you could make hangman with python I knew that this was the game I wanted to make. I loved to play hangman as a kid during breaks on the whiteboard in the classroom.
My hangman has 3 different degrees of difficulty, easy, medium and hard. The player then get 6 lives/attemps to try and guess the correct word that the computer randomizes from lists that I have made.
The choosen word are shown with "_" for each letter. The game also tells the user how many letter the word has in the beginning after the difficulty level is selected.
The lifes are shown as hearts above the hangman picture. So the player easy can see how many tries he/she got left before the game ends. The player wins the gamer if he/she can guess the correct word without losing all the lifes. The players lose if all lifes are lost. When the game is over the player can choose if they want to plat again or not. If they choose to play again the game restart from where the player can choose the difficulty level. If they choose not to play again the game ends.
- The game got 3 different difficulties that the user can choose from in the beginning of the game. Easy, medium and hard. The easy difficulty got up to 4 letters in the choosen word, the medium got up to 6 letters and the hard got up to 9 letters.
- The player got 6 tries to guess the correct word. That is shown as hearts above the picture of the hangman so the player easy can see how many tries he/she got left before they lose.
-
- Here the game checks if the choosen difficulty level is correct. If the player has written something else then easy, medium or hard they get a message that tells them that its invalid and they need to choose either easy, medium or hard.
-
- When the player is going to guess a letter the game checks for several things. The first thing it checks if its the player only guessed one letter. If he/she guessed more then one letter the game shows a message that they need to guess at one letter at a time.
- The second thing the game checks is if the letter is correct or not. If the letter is correct it gets printed out so the player can see where the correct letter is in the choosen word.
- If the guessed letter is wrong the player gets a message that says wrong letter and then shows the letter next to it. Each time the player guess a wrong letter that letter gets printed out next to the text wrong letter. In that way the player can keep track on which letter they already has guessed that are wrong.
- The third thing the game checks is if the guessed letter already has been guessed. If its already been guessed the player get a message that says "You already guessed that"
-
- When the player wins or loses the game he/she get to choose if they want to play again or not. The game then checks if the input the player has choosen is either "yes" or "no". If "yes" the game restarts from where the player get to choose a new difficulty level.
- If the player choose "no" the game ends.
- If the player write something else then "yes" or "no" a message pop up saying that the message is invalid. And then asks them again if they want to play again, and to choose either "yes" or "no"
- The game uses arrays to store the different words which are used for the different difficulties. It also stores the correct and wrong guess in a temporary array. The correct guess array stores the correct letters that the player has guessed, and the wrong guess array stores all the wrong letters who then prints out to the player during the game. When the correct array no longer has any "_" in it the player wins and the win statement is printed out. If the player fails to guess the correct word for 6 tries the losing statement is printed. The 6 tries is stored on the wrong guess array. If the player choose to play again when the game is over the array for the choosen word randomizes a new word through a random.choice generator. So the user dont have to guess on the same word again. The arrays for the correct and wrong answer gets reseted so the game dont store the letters from the last game. The game also uses inputs so the player can choose which difficulty level they want and if they want to play again when the game is over.
- PEP8 to validate python code
- [https://fsymbols.com/generators/] to generate the text for the print "hangman", "You won! Congratulations", "Game over! You lose" and the hearts which shows the lifes
- I tested the game works as it should in Chrome, Firefox and Edge browser.
- I tested that the guess letter input was working as it should by putting wrong inputs such as no letter, double letter or the same letter twice or more to see that the correct prints was printed out.
- I tested that the prints was working trough out the process of making the game by running just that part of the function or method.
- I tested that the variables which generates a random word was working by playing again when the game was over to see that another word was generated and not the same one that i had in the game before.
- I tested that the play again input "yes" worked as it should by choosing "yes" so the game restarts where the player can choose a difficulty.
- I tested that the play again input "no" worked as it should by choosing "no" when the game is over to see that the console ends the game.
- I tested that each function was going through each stage correctly and didnt miss anything or produced any errors
- I tested that all text is easy to read and to understand
- The code got valified through PEP8 that is built in in the IDE i use
-
Ive noticed one bug that only appears sometimes. Its that the game sometimes only print one correct guessed letter ive if the correct word got more then one of that letter. Ive debugged the game by using the word "boo" and "luigi". I have tried the following things to try and locate where the bug happends:
- I tried to guess "o" as the first correct guessed letter in the first game the console runs. The bug didnt show. The game printed out both "o"
- I tried to guess the "b" first then the "o". The bug didnt show. The game printed out both "o"
- I tried to guess the wrong letter 5 times so I only got 1 life left and the guessed "o". The bug didnt show. The game printed out both "o"
- I tried to guess "l" as the correct first letter for the word "luigi". Then guess a wrong letter, to then guess "i". The bug didnt show. Both "i" still printed out
- I tried to end the game early by typing CTRL+C in the terminal. And then restart a new game after that by usin the "up arrow" so the terminal starts the game by printing out "python3 run.py" to see if the bug was going to show. The game still printed out both "i".
- I tried to run several games after eachother by winning or losing the game and choose to play again. The bug still didnt show and printed both "o" to the word boo, and both "i" to the word luigi I still havent found what makes this bug appear.
-
Dont know if this is a bug but when Ive tried to delete trailing spaces in the code they wont go away. Its 11 trailing spaces that wont go away and exists in the code.
This project was deployed via Github to Heroku. Make sure that you have added your dependencies to the requirements.txt file before you do this or it might not work. The following steps shows how you deploy it to Heroku:
- Log in to your Github and create your repository.
- Make a account on the Heroku website if you dont got one already [https://id.heroku.com/login]
- Fork or clone your repository
- Set the buildbacks to Python as the first one, and NodeJS as the second
- Link your Heroku accoun to the correct repository
- Click on deploy
- I looked on these two tutorials on youtube to help me make the game [https://www.youtube.com/watch?v=Ff--def_1q0][https://www.youtube.com/watch?v=7sVnul-StrU]