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

Function askForPlayerMove

src/gamesbyexample/slidingtilepuzzle.py:76–93  ·  view source on GitHub ↗

Let the player select a tile to slide.

(board)

Source from the content-addressed store, hash-verified

74
75
76def askForPlayerMove(board):
77 """Let the player select a tile to slide."""
78 blankx, blanky = findBlankSpace(board)
79
80 w = 'W' if blanky != 3 else ' '
81 a = 'A' if blankx != 3 else ' '
82 s = 'S' if blanky != 0 else ' '
83 d = 'D' if blankx != 0 else ' '
84
85 while True:
86 print(' ({})'.format(w))
87 print('Enter WASD (or QUIT): ({}) ({}) ({})'.format(a, s, d))
88
89 response = input('> ').upper()
90 if response == 'QUIT':
91 sys.exit()
92 if response in (w + a + s + d).replace(' ', ''):
93 return response
94
95
96def makeMove(board, move):

Callers 1

mainFunction · 0.70

Calls 1

findBlankSpaceFunction · 0.85

Tested by

no test coverage detected