Hangman

Today you'll make everybody's favorite pretty-grisly-is-this-actually-appropriate?-children's game Hangman. Before you start, create a directory called lab08, and download this tarball of wordlists to it. Untar it with the command tar xzf words.tgz.

Below is an example of my program running:

taylor@kurt:~/zee/si204/class/lab08$ ./a.out 

What file do you want a word from? words07.txt

-------.  6 wrong guesses left.
  Enter a guess: e
  No E.

-------.  5 wrong guesses left.
  Enter a guess: r
  No R.

-------.  4 wrong guesses left.
  Enter a guess: a
  Yes!  There is a A.

-A---A-.  4 wrong guesses left.
  Enter a guess: s
  No S.

-A---A-.  3 wrong guesses left.
  Enter a guess: g
  Yes!  There is a G.

-A-G-A-.  3 wrong guesses left.
  Enter a guess: n
  Yes!  There is a N.

-ANG-AN.  3 wrong guesses left.
  Enter a guess: f
  No F.

-ANG-AN.  2 wrong guesses left.
  Enter a guess: k
  No K.

-ANG-AN.  1 wrong guesses left.
  Enter a guess: h
  Yes!  There is a H.

HANG-AN.  1 wrong guesses left.
  Enter a guess: b
  No B.

You lose...  The word was HANGMAN.

Of course, if I fill in the entire word before I run out of guesses, I win, instead.

To help you write this program, write the following methods in a file called hangman.cpp:

Once you have these methods, you can hopefully write a main function to implement the full game. Feel free to write any other functions you think would be helpful to you.

It is necessary that your first user input be a filename to draw a random word from, and the remainder of user inputs be letters guessed. Each turn, you should display the blanked-out word, and the number of wrong guesses remaining. At the end of the game, you should display if the player won. Aesthetic decisions are up to you.

Extra challenge

The only thing we haven't done is draw the little man. Rather than having a countdown with the number of guesses remaining, draw the man! To get you started, here's a string that gives you the full hanging man:

  string fh = "  ____\n  |   |\n _O_  |\n  |   |\n / \\  |\n______|_\n";

And here's a string that gives you an empty gallows:

  string ch = "  ____\n  |   |\n      |\n      |\n      |\n______|_\n";

Submission

If in Dr. Taylor's sections, submit with submit lab08

If in Dr. Chambers' secion, submit with submit lab08 hangman.cpp