< Previous | Contents | Next >
Before I write a single line in C++, I plan the game program using pseudocode.
Create a group of words
Pick a random word from the group as the secret word
While player hasn’t made too many incorrect guesses and hasn’t guessed the secret word
Tell player how many incorrect guesses he or she has left Show player the letters he or she has guessed
142 Chapter 4 n The Standard Template Library: Hangman
Show player how much of the secret word he or she has guessed Get player’s next guess
While player has entered a letter that he or she has already guessed Get player’s guess
Add the new guess to the group of used letters If the guess is in the secret word
Tell the player the guess is correct
Update the word guessed so far with the new letter Otherwise
Tell the player the guess is incorrect
Increment the number of incorrect guesses the player has made If the player has made too many incorrect guesses
Tell the player that he or she has been hanged Otherwise
Congratulate the player on guessing the secret word
Although the pseudocode doesn’t account for every line of C++ I’ll write, I think it does a good job describing what I need to do. Then I begin writing the program.