Game Development Reference
In-Depth Information
9 - Hangman
112. while True:
113. displayBoard(HANGMANPICS, missedLetters,
correctLetters, secretWord)
Add the line so your program looks like this:
122. while True:
123. print('The secret word is in the set: ' + secretKey)
124. displayBoard(HANGMANPICS, missedLetters,
correctLetters, secretWord)
Now we are done with our changes. Instead of just a single list of words, the secret word
will be chosen from many different lists of words. We will also tell the player which set of
words the secret word is from. Try playing this new version. You can easily change the
words
dictionary on line 59 to include more sets of words.
Summary
We're done with Hangman. This has been a long chapter, and several new concepts have
been introduced. But Hangman has been our most advanced game yet. As your games get
more and more complex, it'll be a good idea to sketch out a flow chart on paper of what
happens in your program.
Methods are functions that are associated with values. The return values of methods
depend on the values that the method is associated with.
for
loops iterate over the items in a list. The
range()
function is often used with
for
loops because it is an easy way to create lists of sequential numbers.
Else if statements (which use the
elif
keyword) will execute their block if their
condition is
True
and the previous
if
and
elif
conditions are
False
Dictionaries are very similar to lists except that they can use any value for an index. The
indexes in dictionaries are called keys. Keys can be strings, integers, or any value of any
data type.