Skip to content

sategie/hangman-animals-game

Repository files navigation

Hangman: Animals Game

This project is based on the classic Hangman game in which a user has to guess the letters in an unknown word before the game ends. Each player has a fixed amount of lives and if the word is not guessed before the number of lives reaches zero, the player gets hanged.

This version uses only animals and gives the user a total of 6 lives to guess the correct animal.

The game was designed using only the Python language and some in-built libraries.

The project was deployed to Heroku and and runs in a mock terminal which can be viewed in the browser.

Link to Deployed Project

Image of start page of the game in the CLI

Contents

Features

  • Main screen

    • When the game loads, the user is presented with the title of the game and prompted to enter the name.

Image of start page of the game in the CLI

  • Gameplay

    • When the user enters the name field, a 'loading...' message appears for 1 second and then a welcome message is displayed to welcome the user.
    • The game begins with 6 lives
    • There is an empty list in which the guessed letters are displayed in alphabetical order.
    • The user is provided with blank lines in which the letters in the current word have to be guessed
    • If a user guesses the wrong letter, a message appears informing the user that the chosen letter is not in the word and the life is reduced by 1.
    • If a user guesses the correct letter in the word, the letter appears in one of the blank lines and the amount of lives do not change.
    • The amount of lives only reduces when the user guesses a new incorrect letter.
    • If the user tries to use one of the letters which has already been guessed, a message appears informing the user that the letter has already been used and the user is then prompted to guess another letter.
    • The game ends if one of the following applies:
      • The user guesses all correct letters before the number of lives is used up.
      • The number of lives is used up .i.e the user has not guessed the correct word in 6 attempts
    • When the game ends, the correct word is displayed and the user is asked if they want to play again or not.
      • If the user chooses to play again, a message appears welcoming the user back to the game.
      • The number of lives resets back to 6 and the letters in a new random word have to be guessed.
      • If a user chooses not to play again, a message appears thanking the user for playing and the game goes back to the main screen and asks the user to enter a name.

Image showing an example of the actual gameplay

Image showing an example of the actual gameplay

Image showing an example of the actual gameplay

Image showing an example of the actual gameplay

Image showing an example of the actual gameplay

Technologies Used

  • Python: The programming language in which the game is written.

    • The random and time built-in libraries were imported and used in the project to select random words from the word_list and add a delay at certain points in the game respectively.
  • CodeAnywhere: The IDE used for writing the actual Python code.

  • Github: This was used for remote storage and version control.

  • Heroku: This was used to deploy the project.

  • Screenpresso: This was used to make screenshots of the deployed project.

  • Tables Generator: This was used to generate the table used in the Testing and Validation section.

  • prettier.io: This was used to arrange each word in the words list in order to make them appear on separate lines

Testing and Validation

  • Code Institute's Python Linter: No errors were found when the code was checked using the CI Python linter.

Image showing the results of the testing in the CI Python linter

  • Browsers: The link to the deployed project runs in a mock terminal which can be accessed via a web browser. This link was tested in Google Chrome, Microsoft Edge and Firefox. The link worked without any issues on all browsers.

  • Testing and Validation Outcomes

Test Test Action Expected Outcome Result
Run Program Click on 'Run Program' or the refresh button The game reloads with the game title and name input message. PASS
Enter Name Enter name when prompted by the game A 'loading...' message appears for 1 second.
A welcome message appears with the name of the user.
The amount of lives(6) displays.
An empy list is displayed where all the used letters would be placed.
A 'Current word' field is displayed with empty dashes corresponding to the length of the word.
The user is prompted to guess a letter.
PASS
Guess Letter Enter a letter in the 'Guess a Letter' field and click on 'Enter' A message appearing informing whether or not the letter is in the word.
If the letter is in the word, the letter is added to the used letters list and the lives are not reduced.
If the letter is not in the word, the letter is added to the used letters list and the lives are reduced by 1.
PASS
Guess word correctly Guess the correct word before the number of lives is used up. A message appears informing the user that the correct word was guessed.
The correct word is displayed.
The user is asked if they want to play again.
PASS
Fail to guess word Fail to guess the correct word with the assigned number of lives. A message 'Determining your fate...' appears for 2 seconds.
A message appears informing that the user got hanged.
The correct word is displayed.
The user is asked if they want to play again.
PASS
Decide to play again Enter y or Y when asked to play again A message appears welcoming the user back to the game.
The amount of lives(6) displays.
An empty list is displayed where all the used letters would be placed.
A 'Current word' field is displayed with empty dashes corresponding to the length of the word.
PASS
Decide not to play again Enter n or N when asked to play again A message appears thanking the user for playing.
The title of the game is displayed.
The user is prompted to enter a name.
PASS
Name Input Validation Enter any other character apart from a letter The user is prompted to enter only letters. PASS
Case Validation Enter upper case instead of lower case when guessing a letter The upper case is accepted and converted to lower case. PASS
Space Validation Enter a trailing space after the last letter.
Enter a space between the names.
Enter a space before the first letter
The trailing space is ignored and the input is accepted.
The input is accepted with spacing between the names.
The space is ignored and the input is accepted
PASS
Multiple Letters Validation Enter more than one letter when guessing a letter The user is prompted to enter only one letter.
Amount of lives is not reduced.
PASS
Same Letter Validation Enter the same letter which was already guessed The user is informed that the letter has already been used.
The user is prompted to guess another letter.
Amount of lives is not reduced.
PASS
Replay Game Input Validation Enter any other character apart from y or n (lower or capital) The user is prompted to enter either y or n. PASS
  • Unfixed Bugs
    • While the time.sleep function is being run, any letter typed is displayed on the screen.
      • This behaviour can be avoided by waiting until the time.sleep function finishes running.

Deployment

  • The project was deployed to Heroku using the following steps:
  1. A newline (\n) was added at the end of the each input function in the code in order for the code to show up in the Code Institute mock terminal.

  2. Log into Heroku (heroku.com)

  3. Click on the 9 dots (in a square) on the top right corner and select 'dashboard'.

  4. Select the 'New ' icon on the top right and select 'Create new app'.

  5. Give your app a suitable name, choose your region and click on 'Create App'.

  6. Access the Settings tab and click on 'Reveal Config Vars' under the Config Vars section.

  7. Add PORT in the 'key' field and 8000 in the 'value' field.

  8. Click on 'Add Buildpack' in the Buildpacks section.

  9. Select Python and save changes.

  10. Select nodejs and save changes.

  11. Ensure the Python buildback is above the nodejs buildback.

  12. Go to the Deploy section.

  13. Select 'Github' as the deployment method.

  14. Connect to Github and search for the repository name.

  15. Click on 'Connect' to connect the repository with Heroku.

  16. Click on 'Enable Automatic Deploys' (This is optional and simply rebuilds the app each time an update is pushed to Github).

  17. A message appears informing that the app was successfully deployed.

  18. The link to the deployed project is https://hangman-animals-game.herokuapp.com/

  • How to Fork the Repository

    1. Go to the project's Github repository https://github.com/sategie/hangman-animals-game

    2. Click on the Fork button on the top right of the screen.

  • Note: Changes made here do not affect the original repository.

  • How to Clone the Repository

    1. Go to the project's Github repository https://github.com/sategie/hangman-animals-game

    2. Click the green Code button on the right.

    3. Click on HTTPS and copy the link.

    4. Open Git and change the working directory to your preferred location.

    5. Type git clone and paste the copied URL.

    • Changes to the project can be made by doing the following:

      1. Type git add.

      2. Type git commit -m and add a short comment inside quotes .e.g git commit -m "This is an example comment".

      3. Type git push to push the changes to the repository.

    • Note: Any update committed to the main branch immediately reflects in the hosted site.

    Credits

    • Idea for using the time.sleep module was taken from the article "Python sleep(): How to Add Time Delays to Your Code". See Article Here

    Acknowledgements

    • This project would not have been possible without the assistance from my family. For understanding when I had to work longer hours on the project and for supporting me all the way through.

    • My mentor Brian Macharia has helped me a lot with useful tips not only for this project, but also tips on how to become a better developer. For this, I am very grateful.

About

A python project of the classic hangman game with only animal names used.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published