Game Development Reference
In-Depth Information
130. else:
131. missedLetters = missedLetters + guess
132.
133. # Check if player has guessed too many times and
lost
134. if len(missedLetters) == len(HANGMANPICS) - 1:
135. displayBoard(HANGMANPICS, missedLetters,
correctLetters, secretWord)
136. print('You have run out of guesses!\nAfter ' +
str(len(missedLetters)) + ' missed guesses and ' + str(len
(correctLetters)) + ' correct guesses, the word was "' +
secretWord + '"')
137. gameIsDone = True
138.
139. # Ask the player if they want to play again (but only
if the game is done).
140. if gameIsDone:
141. if playAgain():
142. missedLetters = ''
143. correctLetters = ''
144. gameIsDone = False
145. secretWord = getRandomWord(words)
146. else:
147. break
How the Code Works
1. import random
The Hangman program is going to randomly select a secret word from a list of secret
words. This means we will need the random module imported.
2. HANGMANPICS = ['''
3.
4. +---+
5. | |
6. |
7. |
8. |
9. |
10. =========''', '''
...the rest of the code is too big to show here...
This "line" of code a simple variable assignment, but it actually stretches over several real
lines in the source code. The actual "line" doesn't end until line 58. To help you understand
Search WWH ::




Custom Search