Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hangman Pseudo Code 1. Do a nice introduction screen for your hangman program (do this step last). 2. Select a random word and store it

Hangman Pseudo Code

1. Do a nice introduction screen for your hangman program (do this step last).

2. Select a random word and store it in a string variable name SecretWord.

3. Create GuessWord which will be the same size as SecretWord, but all periods (e.g. ". . . . . . . .")

string GuessWord = SecretWord; for (int x = 0; x < SecretWord.size(); x++) { if (SecretWord[x]==' ') GuessWord[x] = ' '; else GuessWord[x] = '.'; }

4. Declare an integer named BadGuesses = 0 Declare a string named Letter Declare an integer named Location

5. Set up a while loop for steps 6 - 10. It should loop as long as BadGuesses < 6 and GuessWord != SecretWord. 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 main while loop in the program

6. Display Graphics (do this step last)

7. Display Letters Already Guessed (do this step last)

8. Cout the GuessWord variable (the placeholder will all periods)

9. Prompt player to enter a letter (their guess) and store it in the variable Letter. Add this letter to LettersGuessed.

10. If Letter is not located in SecretWord (note: use Letter.find( ), increment BadGuesses

Else continue looping and find all occurences of Letter in GuessWord and replace the periods.

// Step 10 Location = SecretWord.find(Letter,0); if (Location > SecretWord.size()) BadGuesses++; else while (Location < SecretWord.size()) { GuessWord.replace(Location,1,Letter); Location = SecretWord.find(Letter, Location + 1); }

}

11. If you exit the loop, then you've either won or lost. Therefore, if BadGuesses == 6, then display "you lose", otherwise display "you win".

Tips - If you do not follow these tips and ask for my help, I will simply tell you to follow these tips.

(a) Comment each step in your code (e.g. // Step 3) (b) Do the graphics (step 1 & 6) last. Do step 7 last. (c) Do each step and then test it - don't try to do the whole program at once (d) Indent your code properly --- after an opening brace, indent

Extra Credit Ideas

To get extra credit on your hangman program, you can implement some of the following ideas:

(a) Outstanding graphics. E.g. add color, clear screen when needed, do a theme.

(b) Ask the user to select a subject for their secret word - e.g. college, movies, etc.

(c) Make your program work with spaces and capitalized letters in the secret word.

(d) Keep score on how many times you've won and lost. The score could be saved to a file. The next time you run the program, it reads the numbers from the file into variables.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago