Date: Mon, 11 Nov 1996 17:52:21 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Wed, 30 Oct 1996 18:40:07 GMT Content-length: 5159
Assigned: 10-30-96
Due: 11-8-96
You are to write a computer Hangman game. In Hangman, one player
picks a word or phrase. She then writes out the phrase with the
letters hidden. For example,
is the hidden form of the Kurt Vonnegut book title
###'# ######
The second player then repeatedly guesses letters in the word.
Suppose he guesses an A. The puzzle would become:
CAT'S CRADLE
But if the user guesses a letter which isnt in the word (for example,
a Q), then he is one step closer to the hangman's gallows. The game
continues until either (1) the user guesses all of the hidden letters
in the puzzle correctly, or (2) the user makes 6 mistakes. If the
user makes 6 mistakes, he loses and the game is over. If the user
guesses all of the letters correctly, he wins and should be given a
congratualatory message.
#A#'# ##A###
____
| |
| O
| /|
|
|
=====
#A#'# ##A###
your guess > C
C is in the puzzle.
____
| |
| O
| /|
|
|
=====
CA#'# C#A###
your guess > Q
Q is not in the puzzle.
____
| |
| O
| /|\
|
|
=====
CA#'# C#A###
...ETC...
The second player should be able to enter his guesses in upper or
lower case. If the player loses, your game should display the correct
solution to the puzzle. It is frustrating to play a game and not be
told the correct answer when you lose. You may handle the case in
which the user enters a letter which has already been chosen in
whatever manner you find appropriate. That is, it may count as
another wrong answer or not. I am allowing you this latitude so that
you can consider different problem-solving alternatives to do the
problem.
The gallows is a visual way of displaying how many wrong guess the
player has made. Initially, with no wrong guesses, the player is
shown an empty gallows:
As the player makes more and more mistakes, more of their bodies is
added to the gallows. First the head:
____
| |
|
|
|
|
=====
Then the body:
____
| |
| O
|
|
|
=====
One arm:
____
| |
| O
| |
|
|
=====
Another:
____
| |
| O
| /|
|
|
=====
A leg:
____
| |
| O
| /|\
|
|
=====
And, when the body is complete, the player has been "hanged", they
lose and the game is over.
____
| |
| O
| /|\
| / \
|
=====
Note that the number of body parts above makes the game over when the
player makes 6 wrong guesses. You are free to add the arms and legs
in whatever order you deem fit. A bit of advice, if you make drawing
the gallows the job of a function
void display_gallows(int wrong);
then you can implement it as a stub function until you want to
actually write it. You don't have to draw the gallows in a
complicated way; feel free to do it in an easy, natural way.
____
| |
| O
| /|\
| \
|
=====
You will somehow need to keep track of (1) the full text of the puzzle (so you can check to see if the user gives a correct answer) and (2) the letters/positions which are revealed (so when you display the puzzle, you can decide which characters to show and which characters to "blank out"). You will probably need two arrays to do this, the first a string to keep track of the "real" answer to the puzzle, the second some sort of array that somehow keeps track of how the displayed puzzle should look. If you get really stuck I can give you more advice.
Hand in output from at least two games of Hangman. The first game should be the puzzle "sCubA" with the guesses 'a', 'E', 'c', 'S', 'd', 'B', and 'u'. The second game can be of your choice.
Mar 95 Written by Todd Turnidge
Oct 96 Modified by Todd Turnidge