Giter VIP home page Giter VIP logo

project-portfolio-24's Introduction

HANGMAN

Portfolio Project 3

Hangman is a Python terminal game, which runs in the Code Institute mock terminal on Heroku. It is a fun game aimed at any English speaking individual or English student. This game can be played at any time for fun or as a brain game.

The game can be found here.

How to play


  • The game begins with a welcome message. The image was generated using the Ascii graffiti generator PatorJK. I ensured the style is easy to read.

  • The game then asks the user to choose a difficulty level. They can select Easy by pressing "E" or Hard by pressing "H" on the keyboard. Easy gives the user 6 tries and Hard gives the user 4 tries, to guess the word. If the user tries to input any other key the game will not accept it and will ask the question again.

  • The game provides an image of the empty gallows with a line of underscores underneath it. This shows the length of the word. The game asks the user to guess a letter or word.

  • The user begins by picking a letter. If they guess correctly, the letter appears on screen in its respective place in the word. The console also provides positive feedback telling the user they are correct. It then prompts the user to input another letter.

  • The player continues to guess letters. If incorrect, a body part appears in the gallows and the console feeds back to the user saying the letter is not in the word and to try again.

  • If the user should guess a letter again, that they already guessed, the console will tell them they already guessed that letter. The player does not lose a life and is prompted to guess again.

  • If the player inputs a guess that is not a letter or word. The computer will feedback that it is not a valid guess and try again. The player will not lose a life.

  • If the player guesses each letter correctly or figures out the word and types it in before they run out of tries and all the body parts appear in the gallows, they are congratulated for guessing the word correctly.

  • If the player runs out of tries and they don't guess the word, they get a game over message and the computer reveals the word. The user is asked whether they would like to play again after each game.

Flowchart

This is my initial plan for the game. Some features have changed as I developed the game.

Features


  • Random word selection
  • The computer randomly selects a word from the word list.
  • The player cannot access this word, only see the length and input word or letter guesses.
  • The user plays against the computer

  • The computer accepts user input and gives responsive feedback

  • Input validation and error-handling

  • You cannot enter a number.
  • You cannot enter a string of letters that isn't equal to the length of the word.
  • You cannot enter the same guess twice.

Testing


Code Validation

  • I tested my code using pycodestyle that i installed into GitHub. I had to fix 'line too long' and 'whitespace' errors. Otherwise there were no errors detected.

Manual Testing

  • At the start of the game the player must select a level. E for Easy or H for Hard. These are the only two letters the computer should accept.
  • Test: To test this, I input the E and H individually, both upper and lower case. I then tried other letters, words, numbers and punctuation keys to see if the game would continue.
  • Result: Adding anything except E or H did not continue the game and the console told the user that their input was not a difficulty and re-asked the question to select E or H.
  • Verdict: Only E and H were accepted so it was a success.

  • The user should only be able to guess a single letter or a word that equals the length of the word they are trying to guess. Any number, punctuation mark or word that is longer or shorter than the one to be guessed should not be accepted.
  • Test: After starting the game and selecting a difficulty, I input words that were longer or shorter than the length of word I was trying to guess, I input numbers and I input symbols.
  • Result: The game did not allow the player to add any symbols, numbers or words that did not equal the correct length. It told the user their input was incorrect and asked them to guess again.
  • Verdict: Only singular letters or words of the correct length were accepted as guesses and allowed the game to continue. The test was a success.

  • The user should only be allowed to guess each letter/word once. If it is already guessed the computer should tell them and they do not lose a life.
  • Test: Whilst playing the game I repeatedly input the same letter/word.
  • Result: The computer prompted me that I had already guessed that letter/word and should try again. No life was lost.
  • Verdict: This test was a success as the game prompted the user with a message and no life was lost.

  • When the user loses a game, "Game Over" should appear with a message to inform the player of the word they were trying to guess.
  • Test: I played the game multiple times trying to guess incorrectly so as to lose.
  • Result: Each time I lost the message popped up correctly at the end of the game.
  • Verdict: The test was a success. The message appeared correctly at the correct point in the game.

  • When the user wins a game, "Well Done" should appear to congratulate the player.
  • Test: I played the game multiple times trying to win.
  • Result: By winning as many times as I could, the message came up at the end of the game.
  • Verdict: The test was a success. Each time I won the game the correct message was displayed at the correct time.

  • When the user finishes the game, whether they win or lose, the game should ask them if they want to play again. The player can input Y for yes or N for no. If they select Y the game should restart, if they select N the terminal clears and the game ends.
  • Test: By finishing the game repeatedly I input Y or N to test the outcome.
  • Result: Y restarted the game, N cleared the terminal and any other key was not accepted.
  • Verdict: The test was a success as the appropriate key carried out the correct function.

Bugs

  • Problem: The Y/N option to restart the game was not working. It just cleared the console.
  • Cause: I had put an if in a while loop. And I had forgotten to put parentheses after the .upper โ€œ"Are you brave enough to try again? (Y/N) ").upper() == "Y":โ€
  • Resolution: I reformatted my while statement and added in my parentheses. The function then worked.

Technologies


Languages

  • Python: This whole project was written using Python.
  • Markdown: The READ ME is written using Markdown.

Environment

  • GitHub: was used to host the code.
  • GitPod: was used to write the code.
  • Heroku: was the cloud hosting platform used to deploy this project.

Packages

  • Colorama: was used to create coloured text and images in the game.

Other

  • Graffiti:was used for the large text images in the game.

Deployment


  • I committed and pushed all code for the game to GitHub from GitPod.
  • I created an account on Heroku.
  • I clicked on 'New' and clicked 'Create New App'.
  • I then chose the correct region, Europe and created a name for my app.
  • In settings I sorted out the Buildpacks for everything to work.
  • I inputted the python and nodejs buildpacks.
  • I then put in the config var PORT 8000.
  • I then clicked on the deploy page and linked my GitHub repo with the Heroku app.
  • I then deployed the branch at the bottom of the page, ensuring no errors occurred.
  • I enabled automatic deploys so if I edit and push the code to GitHub, Heroku automatically updates and redoploys.
  • I then opened the game on Heroku to ensure it functions efficiently and checked for any errors that may have occurred.

References


  • I watched multiple tutorials on YouTube to understand the basics of Hangman code in Python. The Kite was especially helpful and helped me to understand the what and why of my code.
  • I used Random Words Generator to get my words for the game. I was able to tailor the length and chose 50 words for each length.

Acknowledgements


  • I'd like to thank my mentor Richard Wells for all of the help and support throughout.
  • Thank you to my family and friends for testing and feedback.
  • Thank you to my peers on Slack for always being supportive.

Evangeline MIlls 2022

project-portfolio-24's People

Contributors

evangelinemills 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.