Game Development Reference
In-Depth Information
return True if the string consists solely of numbers. Otherwise it returns False . Try
typing the following into the interactive shell:
>>> '42'.isdigit()
True
>>> 'forty'.isdigit()
False
>>> ''.isdigit()
False
>>> 'hello'.isdigit()
False
>>> x = '10'
>>> x.isdigit()
True
>>>
As you can see, both move[0].isdigit() and move[1].isdigit() must be
True . The final part of this expression calls our move[1] function to check if the XY
coordinates exist on the board. If all these expressions are True , then this function returns
a two-integer list of the XY coordinates. Otherwise, the player will be asked to enter
coordinates again.
Asking the Player to Play Again
109. def playAgain():
110. # This function returns True if the player wants to
play again, otherwise it returns False.
111. print('Do you want to play again? (yes or no)')
112. return input().lower().startswith('y')
The playAgain() function will ask the player if they want to play again, and will
keep asking until the player types in a string that begins with 'y' . This function returns a
Boolean value.
Printing the Game Instructions for the Player
115. def showInstructions():
116. print('''Instructions:
117. You are the captain of the Simon, a treasure-hunting
ship. Your current mission
118. is to find the three sunken treasure chests that are
lurking in the part of the
119. ocean you are in and collect them.
120.
121. To play, enter the coordinates of the point in the ocean
Search WWH ::




Custom Search