4.8.1 游戏规划
在用C++(www.cppentry.com)写代码之前,用伪代码对该游戏程序进行规划。
- 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
- 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
尽管伪代码没有说明要编写的每一行代码,但它很好地描述了需要做的工作。接下来我们开始编写程序。