CPE 101:
Fundamentals of Computer Science 1


Spring 2003
(Sections 02 & 03 only)
Program # 5
Due by 9 pm onWednesday of Week # 9.
Note: This assignment may be done with one partner.
In that case, submit only one copy, but completely
document both partner's roles in your write-up.

See new version of HangedMan.java
with one change only, at line #66.


(Now DEAD matches number of switch cases.)


Task Navigation Links:
| The Game | Some Helper Files |
| Your Task | Sample Output |
| Submitting Your Work |

The Hangman Game

Hangman is a two player game word game where one player chooses a word and the other tries to figure out what the word is by guessing letters in it. In this game the role of the first player (who chooses the word) will be played by the computer.

The play goes as follows: The computer will guess a word and show it to the player as a series of dashes, one for each letter in the word. The player is then asked to guess a letter. If the letter is in the word, any blanks corresponding to that letter are filled in. If the letter is not in the word, the player moves one step closer to losing. This is indicated by adding another body part to a stick figure hanging from a gallows. If the full figure is completed before the word is completely guessed, the player is dead and, thus, loses. (Children's games are often such sweet, gentle activities, aren't they?)


Some Helper Files

To help you along, the following classes are provided:

Dictionary.java

HangedMan.java

You should just compile and use these two classes as they are. Do not edit them! In theory, you should be able to use them from just the information provided above but, if you are interested in how either of these work, do feel free to look at their implementation.


Your Task

Write a program, Hangman.java, that will do the following:

Some hints:


Sample Output

% java Hangman
I'm thinking of a word.  It has 4 letters.
        ______    
        |    |    
        |         
        |         
        |         
        |         
        |________ 

        ____

Guess? e
I'm sorry, there is no 'e'.
        ______    
        |    |    
        |    O    
        |         
        |         
        |         
        |________ 

        ____

Guess? s
I'm sorry, there is no 's'.
        ______    
        |    |    
        |    O    
        |    |    
        |         
        |         
        |________ 

        ____

Guess? g
I'm sorry, there is no 'g'.
        ______    
        |    |    
        |    O    
        |    |    
        |    |    
        |         
        |________ 

        ____

Guess? a
I'm sorry, there is no 'a'.
        ______    
        |    |    
        |    O    
        |   /|    
        |    |    
        |         
        |________ 

        ____

Guess? l
I'm sorry, there is no 'l'.
        ______    
        |    |    
        |    O    
        |   /|\   
        |    |    
        |         
        |________ 

        ____

Guess? m
I'm sorry, there is no 'm'.
        ______    
        |    |    
        |    O    
        |   /|\   
        |    |    
        |   /     
        |________ 

        ____

Guess? w
I'm sorry, there is no 'w'.
        ______    
        |    |    
        |    O    
        |   /|\   
        |    |    
        |   / \   
        |________ 
I'm sorry, you seem to have died.
The word was "tonk"

Again? yes
I'm thinking of a word.  It has 6 letters.
        ______    
        |    |    
        |         
        |         
        |         
        |         
        |________ 

        ______

Guess? m
I'm sorry, there is no 'm'.
        ______    
        |    |    
        |    O    
        |         
        |         
        |         
        |________ 

        ______

Guess? M
You have already guessed 'm'.
Guess again: m
You have already guessed 'm'.
Guess again: 8
I'm sorry, '8' is not a letter.
Guess again: g
I'm sorry, there is no 'g'.
        ______    
        |    |    
        |    O    
        |    |    
        |         
        |         
        |________ 

        ______

[... In the interest of space, I'll skip a bit ...]

Guess? a
There is a letter 'a'.
        ______    
        |    |    
        |    O    
        |   /|\   
        |    |    
        |   /     
        |________ 

        fia_co

Guess? s
There is a letter 's'.
        ______    
        |    |    
        |    O    
        |   /|\   
        |    |    
        |   /     
        |________ 
Congratulations, you got "fiasco!"

Again? n		(Thinking, "That was just too close...")

%

Submitting Your Work

Use the "handin" facility available from your Central Unix account on Polylog1 to submit your game file:

It is expected that your source code will contain full internal documentation. Use the standard comment block at the beginning of the program for your design specifications and other general information. Use comments throughout your programs to clarify to anyone reading your program what you are doing at each step along the way. If you have additional comments to make, you may submit a supplemental README document, in plain text format, but its existence must be documented in the program file you submit.

You are not to edit either of the two files you were given and, thus, you should not submit copies of those. Your code must run with your instructor's copy of those files.

Instructions about handin are given on preceeding pages on this site. You will submit to the "Pgm5" folder by 9 pm, Wednesday of the 9th week.


Site Navigation Links:
Back: This Instructor's CSC-101 HomePage
Up: This Instructor's HomePage

Copyright © 2000-01 by Clark S. Turner and Phil Nico and Carol Scheftic. All rights reserved.
Requests to reuse information from this page should be directed to Carol Scheftic.
Page created 1 April 2001; last updated 28 May 2001.