UMBC CMSC201, Computer Science I, Spring '97

Project 4: Hangman

Due: Thursday, April 24, 1997

Your assignment is to write a program that allows the user to play the game Hangman. This will give you practice using graphics, strings, random numbers, and separate compilation.


Description of Hangman

The player plays against the computer. The computer randomly selects a word, and the player tries to guess what the word is. As the player makes mistakes, a picture is drawn. The game is called hangman because of this drawing. The drawing starts out as an empty gallows. Each time the player makes a mistaken guess, a body part is added to the drawing: On the first miss, a head is drawn, on the second miss a torso is drawn, and so on. If the player guesses the word before he is hanged (has all of his body parts), he wins.

At each turn, the player guesses either a letter or the whole word. Suppose it's a letter: If the chosen letter is in the word, all occurrences of that letter are displayed and the player is given another chance to guess a letter. If the letter does not appear in the word, then the guess misses and a body part is drawn as described above.

The player can choose to guess the whole word instead of guessing a letter. If the player guesses the word correctly, he wins. If not the game can continue, but a new body part will be drawn, because the word was missed.

There are eight body parts: head, torso, leftArm, rightArm, leftLeg, rightLeg, leftFoot and RightFoot. With each miss, these body parts should be added to the drawing in the order shown.


A Sample Run with a Description of the Drawing

Welcome to Hangman
(The drawing of the gallows is displayed in the graphics window)

_ _ _ _ _ _

Letters guessed:

Please enter a letter:  (Player types an e)


_ _ _ _ _ e

Letters guessed: e

Please enter a letter:  (Player types a t)


_ _ _ _ _ e

Letters guessed: e t
(The head is drawn, because the letter t wasn't in the word)

Please enter a letter:  (Player types an a)


_ _ a _ _ e

Letters guessed: e t a

Please enter a letter:  (Player types an r)


_ r a _ _ e

Letters guessed: e t a r

Please enter a letter:  (Player types a c)


_ r a n _ e

Letters guessed: e t a r c
(The torso is drawn, because the letter c wasn't in the word)

Please enter a letter:  (Player types a g)


_ r a n g e

Letters guessed: e t a r c g

Please enter a letter: (Player enters an o)

o r a n g e

Correct.  The word was orange.
Congratulations ! You have lived to play another day.


More details

The word to be used for a new game must be chosen randomly from the 10 words shown below.
strong    quaint    garage    apples    budget
answer    matter    dollar    pursue    please

For each turn, you should do the following:


What to Turn In

You must use separate compilation for this project and should have one file, called drawing.c, that contains all of the drawing functions that you write. The file drawing.c will have it's own header file that contains the prototypes for the functions defined in drawing.c. That header file will be named drawing.h.

Your program will consist of at least three files, including drawing.c, drawing.h, and your main program, hangman.c. To submit you will use the submit command, but you must list all of the files, like this: submit cs201 proj4 hangman.c graphics.c graphics.h The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile your project are listed.


Honors Project or Extra Credit

Allow the user to increase the difficulty of the game by choosing to guess words up to ten letters long. You will need to add 10 seven-letter words, 10 eight-letter words, ... , 10 ten-letter words to your program. The user will get to choose the length of the word, but the current word will still be chosen at random from the appropriate list of ten words.