Hangman
Short Description:
Implement the game of Hangman
This assignment is worth 0 points.
Goals
When you finish this homework, you should:
- Have reviewed basic C++ and refreshed your programming skills.
- Have reviewed and strengthened your design skills.
- Have reviewed and strengthened your skills with functions.
- Demonstrated your ability to manipulate strings.
- Demonstrated you ability to use input files.
Formal Description
The game of hangman is played between two players, let's call them a judge and a suspect. The judge selects a word (or phrase) and tells the suspect how many letters are in the word. The suspect then tries to figure out the word by guessing letters. Each time the suspect guesses a correct letter, all of the occurrences of this letter are displayed, in the proper position. If the suspect guesses an incorrect letter, the judge adds another part to a picture of the suspect who is to be hanged on the gallows.
The figure displayed is as follows:
Incorrect Guess Number | Body Part Added | Symbol |
1 | Head | 0 |
2 | Left Arm | \ |
3 | Right Arm | / |
4 | Torso | | |
5 | Left Leg | / |
6 | Right Leg | \ |
The final figure, if the suspect loses will be
\0/
|
/ \
For this game, your program will assume the role of the judge, and the user will be the suspect. Since your program can not "think" of a word or phrase, the data will be stored in a file, phrases.txt. The data will be stored one entry per line and can include spaces. This file contains at least one valid data entry.
Assume the first word in the file is Hangman.
The judge should begin by presenting the suspect with a picture of the gallows, blanks for each letter in the word, and current conditions, such as the turn, the letters guessed which were incorrect, and other information. The following is an example for the output. Your output need not match exactly, but should be similar.
+--+
|
|
|
|
++++++++ _ _ _ _ _ _ _
Turn: 1
Incorrect Letters:
Guess a letter: => E
Your guess of E is incorrect.
Added Head!
+--+
| 0
|
|
|
++++++++ _ _ _ _ _ _ _
Turn: 2
Incorrect Letters: E
Guess a letter: => t
Your guess of T is incorrect.
Added Left Arm!
+--+
| \0
|
|
|
++++++++ _ _ _ _ _ _ _
Turn: 3
Incorrect Letters: E,T
Guess a letter: => A
There are 2 of the letter A
+--+
| \0
|
|
|
++++++++ _ A _ _ _ A _
Turn: 3
Incorrect Letters: E,T
Guess a letter: =>
The program should proceed in this manner until either the suspect figures out the word, or has six incorrect guesses. The player is either pronounced the winner, or given the answer to the puzzle. Finally they are asked to play again, and the process in repeated.
When the player declines to play again, they are given their score (m wins and n losses) and thanked for playing.
Discussion
- Note that the case of the letters does not matter.
- Incorrect input (digits, symbols and such) should not be accepted.
- Whenever possible, eliminate repeated code by building subroutines. If you find you are repeating code, pull it out and put it into a subroutine.
- You may not use string streams for this project.
- If you need help, you should ask.
- Please do not put this work off until the weekend before it is due.
- If you reach the end of this input file, your program should start over at the beginning.
- Non-alphabet letters in the word or phrase should just be printed. "_" is illegal in a phrase.
Required Files
- All source code required to build all programs.
You should not submit
- Object files or executable.
- Core files.
- Source code files which are not related to the project.
Submission
Email your source code to danbennett360@gmail.com by class time of the due date.