CSCI 201 Fall 2000

Assignment 5

Program: Hangman

The program as developed in class

The following classes have been partially completed, you are to use them in completing a program for playing hangman as described below.

In addition, the program hang.cpp shows how the classes can be used. It's not a complete version of a game, but it's something to use to get started.

Requirements

Specifying the Word Source

Your program should take words from the file mywords.txt. In reading words from that file, the class WordSource should return any word in the file with equal probability. You can do this using either a Dice object or a RandGen object. The files that you need to create objects of these types were provided in assignment 3. You can read the words directly from a file or read the words into a StringSet object, either approach is acceptable. If you chose to use a StringSet object, you will have to add a StringSet variable to the private section of the class definition. The files needed to create StringSet objects were provided in assignment 4.

Playing the Game

You can write new classes, or just add to the existing classes, but the final game must have the following properties:
  1. A letter that has already been guessed can be guessed again with no penalty. This means guessing 'a' twice counts for only one miss if 'a' is not in the word.

  2. Before each guessed letter, the user should be shown a list of letters that have already been guessed, along with the word being guessed. The word being guessed may be partially revealed if some letters have been guessed.

  3. Before each guessed letter, the user should be told how many misses are left until being hung (when the game is over).

  4. After a game, either a win or a loss, the user should be asked if she wants to play again.

10 PTS Extra Credit

You can get extra credit for printing a picture/diagram of someone being hung using ASCII art, for example:
   +-----+
   | 0 0 |
   |  -  |
   | --- |
   +-----+
      |
      |
+-----|-----+
      |
      |
     / \
    /   \
   /     \
--/       \--

If you do this, you should use a class Gallows to create the picture.

Some Helpful Hints

Submitting Programs

The programs written for this assignment must be turned in by transferring the C++ source code files to your ftp directory for this class. In this assignment, you will need to submit all code that you have written, this should include: letters.h, letters.cpp, wordsource.h, wordsource.cpp, hang.cpp and the .h and .cpp files for any other classes that you write for this assignment. All of these files should be transfered to your class ftp directory.