Hangman is a game where one player thinks of a word and draws a gallows. The other player tries to guess the word by guessing a letter at a time. If the player correctly guesses a letter, the first player reveals where in the word that letter occurs. If the player's guess in incorrect, the first player adds another part of a body to the gallows. The game ends when either an entire body is on the gallows (in which case the first player wins) or when every letter of the word is guessed.
Below are the data definitions for letters, words and body-parts. The definition for words is incomplete and is only meant as a guideline.
The first player is your hangman program. It randomly selects a word from the WORD dictionary and allows the user to guess. Here are the responses that the program will provide:
Now, let's look at an example run where the procedure (hangman) choses the initial word and (hangman-guess guess) determines which of the four responses is appropriate given the guess and the word.
The dialog shows two rounds of hangman. The player loses the first round of hangman. Also, while a first guess of 'a yields a positive Good Guess! the second guess of 'a yields a lost body part (since 'a had already been guessed). The second round of hangman begins with a call to hangman which resets the game and chooses a new word. The round is won by the player.