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

Function askForPlayerMove

src/gamesbyexample/sonar.py:103–121  ·  view source on GitHub ↗

Returns an (x, y) tuple of the player's move.

(previousMoves)

Source from the content-addressed store, hash-verified

101 return 'Sonar did not detect anything. All treasure chests out of range.'
102
103def askForPlayerMove(previousMoves):
104 """Returns an (x, y) tuple of the player's move."""
105 print('Where do you want to drop the next sonar device?')
106 print('(0-59 0-14 or enter QUIT)')
107 while True:
108 move = input('> ')
109 if move.upper() == 'QUIT':
110 print('Thanks for playing!')
111 sys.exit()
112
113 move = move.split()
114 if len(move) == 2 and move[0].isdecimal() and move[1].isdecimal() and isOnBoard(int(move[0]), int(move[1])):
115 if [int(move[0]), int(move[1])] in previousMoves:
116 print('You already moved there.')
117 continue
118 return (int(move[0]), int(move[1]))
119
120 print('Enter a number from 0 to 59, a space, then a number')
121 print('from 0 to 14.')
122
123def showInstructions():
124 """Display the game instructions."""

Callers 1

sonar.pyFile · 0.70

Calls 1

isOnBoardFunction · 0.70

Tested by

no test coverage detected