Saturday, December 17, 2016

Programming Projects for Beginners - Hangman

This is the classic hangman game where the user guesses the chosen word in a given number of tries.

Note: If you stumbled upon this post and are wondering what this is about, start here.

Here is the usecase:
- Program asks user to guess a letter that makes up the chosen word
- User enters a letter
- Program checks if that letter is part of the word
- If the letter is not part of the word, the program starts drawing the hangman
- If the letter is part of the word, the program displays that part of the word and asks for the next letter
- If user keeps making guessing incorrect letters, the program continues to draw the hangman
- After several bad guesses, once the hangman drawing is complete, the user loses
- If the user guesses the word, the user wins

Programming constructs used:
- User input
- Comparison
- Looping
- Conditional statements
- Error handling
- Exception handling

Here is what a sample output would look like:

Another sample execution:

Hint:
For the hangman, create a list of the ASCII pictures with increasing degree of completion, and display them accordingly.

Bonus:
Read the list of words from a local file on disk.
Account for words with repeated letters.
Account for user typing an already found letter.

Happy coding!