Because of the additional organizational work and the fact that there are more details to manage, you are strongly encourage to work in teams of two for this assignment.
Look on pages 519-521 of the book (Chapter 14 Programming Exercise #12) for a more complete description of the Hangman game. For your version, you will use phrases rather than single words for the user to guess.
There are two important requirements for this assignment:
One good turn deserves another She gets confused flying over the dateline If I can't dance I don't want to be part of your revolution A rolling stone gathers no moss Nothing in all the world is more dangerous than sincere ignorance and conscientious stupidity hello, Is anybody out there?
If you add graphics, you should design and test your program in two parts. First, get the interactive part working without any graphics at all. Once that part is done, make a copy of it, and then add code to draw the Hangman picture using the graphics library functions from Chapter 7.
============================== run 1: the user wins the game ============================== % ./a.out Let's play hangman! I will pick a secret phrase On each turn, you guess a letter. If the letter you guess is in the secret phrase, I will show you where it appears. You only get 8 incorrect guesses. Good luck. Please enter the name of the words file: blah Could not open file blah, try again Please enter the name of the words file: dict.txt Secret phrase: - - - - - - - - - - - - - - - - - - - - - - - - - - You have 8 guesses left Letters guessed: Your guess (enter ! to quit): a That guess is correct. Secret phrase: A - - - - - - - - - - - - - A - - - - - - - - - - - You have 8 guesses left Letters guessed: A, Your guess (enter ! to quit): b There are no B's in the phrase Secret phrase: A - - - - - - - - - - - - - A - - - - - - - - - - - You have 7 guesses left Letters guessed: A, B, Your guess (enter ! to quit): c There are no C's in the phrase Secret phrase: A - - - - - - - - - - - - - A - - - - - - - - - - - You have 6 guesses left Letters guessed: A, B, C, Your guess (enter ! to quit): d There are no D's in the phrase Secret phrase: A - - - - - - - - - - - - - A - - - - - - - - - - - You have 5 guesses left Letters guessed: A, B, C, D, Your guess (enter ! to quit): e That guess is correct. Secret phrase: A - - - - - - - - - - - E - A - - E - - - - - - - - You have 5 guesses left Letters guessed: A, B, C, D, E, Your guess (enter ! to quit): f There are no F's in the phrase Secret phrase: A - - - - - - - - - - - E - A - - E - - - - - - - - You have 4 guesses left Letters guessed: A, B, C, D, E, F, Your guess (enter ! to quit): . .'s not an alphabetic character, try again Your guess (enter ! to quit): a You already guessed A, try again. Your guess (enter ! to quit): F You already guessed F, try again. Your guess (enter ! to quit): r That guess is correct. Secret phrase: A R - - - - - - - - - - E - A - - E R - - - - - - - You have 4 guesses left Letters guessed: A, B, C, D, E, F, R, Your guess (enter ! to quit): o That guess is correct. Secret phrase: A R O - - - - - - - O - E - A - - E R - - O - O - - You have 4 guesses left Letters guessed: A, B, C, D, E, F, O, R, Your guess (enter ! to quit): l That guess is correct. Secret phrase: A R O L L - - - - - O - E - A - - E R - - O - O - - You have 4 guesses left Letters guessed: A, B, C, D, E, F, L, O, R, Your guess (enter ! to quit): i That guess is correct. Secret phrase: A R O L L I - - - - O - E - A - - E R - - O - O - - You have 4 guesses left Letters guessed: A, B, C, D, E, F, I, L, O, R, Your guess (enter ! to quit): n That guess is correct. Secret phrase: A R O L L I N - - - O N E - A - - E R - N O - O - - You have 4 guesses left Letters guessed: A, B, C, D, E, F, I, L, N, O, R, Your guess (enter ! to quit): g That guess is correct. Secret phrase: A R O L L I N G - - O N E G A - - E R - N O - O - - You have 4 guesses left Letters guessed: A, B, C, D, E, F, G, I, L, N, O, R, Your guess (enter ! to quit): s That guess is correct. Secret phrase: A R O L L I N G S - O N E G A - - E R S N O - O S S You have 4 guesses left Letters guessed: A, B, C, D, E, F, G, I, L, N, O, R, S, Your guess (enter ! to quit): t That guess is correct. Secret phrase: A R O L L I N G S T O N E G A T - E R S N O - O S S You have 4 guesses left Letters guessed: A, B, C, D, E, F, G, I, L, N, O, R, S, T, Your guess (enter ! to quit): h That guess is correct. Secret phrase: A R O L L I N G S T O N E G A T H E R S N O - O S S You have 4 guesses left Letters guessed: A, B, C, D, E, F, G, H, I, L, N, O, R, S, T, Your guess (enter ! to quit): m That guess is correct. You guessed the phrase A ROLLING STONE GATHERS NO MOSS. You Win!!! You only had 4 wrong guesses ============================== run 2: the user loses the game ============================== % ./a.out Let's play hangman! I will pick a secret phrase On each turn, you guess a letter. If the letter you guess is in the secret phrase, I will show you where it appears. You only get 8 incorrect guesses. Good luck. Please enter the name of the words file: dict.txt Secret phrase: - - - - - - - - - - - - - - - - - - - - - - - - - - You have 8 guesses left Letters guessed: Your guess (enter ! to quit): a That guess is correct. Secret phrase: A - - - - - - - - - - - - - A - - - - - - - - - - - You have 8 guesses left Letters guessed: A, Your guess (enter ! to quit): r That guess is correct. Secret phrase: A R - - - - - - - - - - - - A - - - R - - - - - - - You have 8 guesses left Letters guessed: A, R, Your guess (enter ! to quit): o That guess is correct. Secret phrase: A R O - - - - - - - O - - - A - - - R - - O - O - - You have 8 guesses left Letters guessed: A, O, R, Your guess (enter ! to quit): l That guess is correct. Secret phrase: A R O L L - - - - - O - - - A - - - R - - O - O - - You have 8 guesses left Letters guessed: A, L, O, R, Your guess (enter ! to quit): x There are no X's in the phrase Secret phrase: A R O L L - - - - - O - - - A - - - R - - O - O - - You have 7 guesses left Letters guessed: A, L, O, R, X, Your guess (enter ! to quit): z There are no Z's in the phrase Secret phrase: A R O L L - - - - - O - - - A - - - R - - O - O - - You have 6 guesses left Letters guessed: A, L, O, R, X, Z Your guess (enter ! to quit): y There are no Y's in the phrase Secret phrase: A R O L L - - - - - O - - - A - - - R - - O - O - - You have 5 guesses left Letters guessed: A, L, O, R, X, Y, Z Your guess (enter ! to quit): p There are no P's in the phrase Secret phrase: A R O L L - - - - - O - - - A - - - R - - O - O - - You have 4 guesses left Letters guessed: A, L, O, P, R, X, Y, Z Your guess (enter ! to quit): q There are no Q's in the phrase Secret phrase: A R O L L - - - - - O - - - A - - - R - - O - O - - You have 3 guesses left Letters guessed: A, L, O, P, Q, R, X, Y, Z Your guess (enter ! to quit): r You already guessed R, try again. Your guess (enter ! to quit): s That guess is correct. Secret phrase: A R O L L - - - S - O - - - A - - - R S - O - O S S You have 3 guesses left Letters guessed: A, L, O, P, Q, R, S, X, Y, Z Your guess (enter ! to quit): m That guess is correct. Secret phrase: A R O L L - - - S - O - - - A - - - R S - O M O S S You have 3 guesses left Letters guessed: A, L, M, O, P, Q, R, S, X, Y, Z Your guess (enter ! to quit): n That guess is correct. Secret phrase: A R O L L - N - S - O N - - A - - - R S N O M O S S You have 3 guesses left Letters guessed: A, L, M, N, O, P, Q, R, S, X, Y, Z Your guess (enter ! to quit): w There are no W's in the phrase Secret phrase: A R O L L - N - S - O N - - A - - - R S N O M O S S You have 2 guesses left Letters guessed: A, L, M, N, O, P, Q, R, S, W, X, Y, Z Your guess (enter ! to quit): u There are no U's in the phrase Secret phrase: A R O L L - N - S - O N - - A - - - R S N O M O S S You have 1 guesses left Letters guessed: A, L, M, N, O, P, Q, R, S, U, W, X, Y, Z Your guess (enter ! to quit): i That guess is correct. Secret phrase: A R O L L I N - S - O N - - A - - - R S N O M O S S You have 1 guesses left Letters guessed: A, I, L, M, N, O, P, Q, R, S, U, W, X, Y, Z Your guess (enter ! to quit): b There are no B's in the phrase Sorry, you lose. The phrase was A ROLLING STONE GATHERS NO MOSS. ============================== run 3: the user quits the game ============================== % ./a.out Let's play hangman! I will pick a secret phrase On each turn, you guess a letter. If the letter you guess is in the secret phrase, I will show you where it appears. You only get 8 incorrect guesses. Good luck. Please enter the name of the words file: dict.txt Secret phrase: - - - - - - - - - - - - - - - - - - - - - - - - - - You have 8 guesses left Letters guessed: Your guess (enter ! to quit): o That guess is correct. Secret phrase: O - - - O O - - - - - - - - - - - - - - - O - - - - You have 8 guesses left Letters guessed: O, Your guess (enter ! to quit): g That guess is correct. Secret phrase: O - - G O O - - - - - - - - - - - - - - - O - - - - You have 8 guesses left Letters guessed: G, O, Your guess (enter ! to quit): ! You quit Sorry, you lose. The phrase was ONE GOOD TURN DESERVES ANOTHER.