Homework 7
Upload your .cpp source code file to Ecampus.
This program is a word/phrase guessing game similar to the classic hangman game. You should create your own theme (not hangman nor one of the themes copied from the Internet).
| 20% Introduction screen | The opening screen should introduce your original theme. It should include ASCII art and color. |
| 20% Winning and losing screens | These screens should match your theme and include ASCII art and color. |
| 20% Game loop ASCII art | The game loop should display color ASCII art that changes with each incorrect guess. It should match your theme. |
| 40% Everything else |
Steps in the program:
1. Introduction Screen
2. Select a random word and store it
in a string variable name SecretPhrase
3. Create GuessPhrase which will be the same size as SecretPhrase, but all periods (e.g. ". . . . . . . .")
| string GuessPhrase =
SecretPhrase; for (int x = 0; x < SecretPhrase.size(); x++) { if (SecretPhrase[x]==' ') GuessPhrase[x] = ' '; else GuessPhrase[x] = '.'; } |
4. Declare an integer named BadGuesses = 0
Declare a string named Letter
Declare a string named LettersRemaining and make it equal to
the alphabet
Declare an integer named Location
5. Set up a while loop for steps 6 - 10. This is the main loop of the program. The game keeps playing as long as you haven't lost (when BadGuesses = 6) and you haven't won (when GuessWord = SecretWord).
{ // This is the opening brace for the game loop
6. Display Game Loop ASCII art graphics (do this step last)
7. Display letters remaining
8. Output GuessPhrase
9. Prompt player to enter a letter (their guess) and store it in the variable Letter. Remove this letter from LettersRemaining.
10. If Letter is not located in SecretPhrase (note: use Letter.find( ), increment BadGuesses
Else continue looping and find all occurrences of Letter in GuessWord and replace the periods.
| //
Step 10 Location = SecretPhrase.find(Letter,0); if (Location == -1) // not found BadGuesses++; else while (Location < SecretPhrase.size()) { GuessPhrase.replace(Location,1,Letter); Location = SecretPhrase.find(Letter, Location + 1); } |
}
11. If you exit the loop, then you've either won or lost. Therefore, if BadGuesses == 6, then display the losing screen, else display the winning screen.