MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / askForPlayerMove

Function askForPlayerMove

src/gamesbyexample/sokoban.py:210–230  ·  view source on GitHub ↗
(maxLevelNum)

Source from the content-addressed store, hash-verified

208
209
210def askForPlayerMove(maxLevelNum):
211 # Get the input from the player:
212 while True:
213 move = input('Enter move> ').upper()
214
215 if move == 'QUIT':
216 print('Thanks for playing!')
217 sys.exit()
218
219 if move.isdecimal():
220 if not (1 <= int(move) < maxLevelNum):
221 # There's no level for the number the player entered:
222 print('Level numbers are between 1 and', maxLevelNum)
223 continue
224 return str(int(move) - 1) # Return the new level number.
225
226 # Check that the input is a valid WASD move or U for undo:
227 if move in ('W', 'A', 'S', 'D', 'U'):
228 return move
229
230 print(move, 'is not valid. Enter W, A, S, D, UNDO, or QUIT.')
231
232
233# If this program was run (instead of imported), run the game:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected