CSci 150: Foundations of computer science I
Home Syllabus Assignments Tests

Assignment 11: Hangman I

Due: 2:00pm, Monday, November 2. Value: 30 pts. Submit to Sauron.

Hangman is a popular (and morbid) children's game, commonly played with a sheet of paper. In it, one child thinks of a word and writes onto a sheet of paper a one blank for each letter, with a picture of a noose below.

In this case, the child has indicated a seven-letter word. The other child then guesses a letter. If the letter is in the word, the first child fills in any blanks occupied by that letter. Suppose, for example, that the first guess is a. The first child might then write:

Perhaps the next guess is e, which happens not to be in the word. The first child draws a head inside the noose.

-------
-a---a-
-a---a-

As the game continues, the picture becomes more complete with each wrong guess.

Guess t i n s h r l
Result -a---a- -a---a- -an--an -an--an han--an han--an han--an

After guessing l, the picture is complete, and the guesser has lost the game. This takes a total of six wrong guesses (the head, the torso, one arm, other arm, one leg, other leg). If the word is completed before the six wrong guesses, the guesser wins.

Over the course of two assignments, we will build a computer version for playing the role of the first child, thus saving you the bother of finding a child against whom to play the game. Our first step is to build a class named Hangman, which will fit into the bigger program. Since we don't have this bigger program yet, for this assignment I am providing Test.java, which you can use for testing your class.

Your Hangman class should extend the GCompound class and provide the following constructor and methods.

Hangman()

(Constructor) Constructs an empty hangman. Something should be displayed initially: It may be a noose (as above) or a gallows (the more traditional technique, illustrated at right).

(Suggestion: Create and add all components of the hangman in the constructor, but hide them using the setVisible method. I am not looking for artistic talent in this assignment — a stick figure is fine — but what you draw should resemble a person.)

void step()

Reveals the next portion of this hangman.

boolean isDone()

Returns true if all portions of the hangman are revealed.

void reset()

Resets this hangman back to his initial state of showing just the gallows/noose.