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

Function displayBoard

src/gamesbyexample/hungryrobots.py:121–137  ·  view source on GitHub ↗

Display the board, robots, and player on the screen.

(board, robots, playerPosition)

Source from the content-addressed store, hash-verified

119
120
121def displayBoard(board, robots, playerPosition):
122 """Display the board, robots, and player on the screen."""
123 # Loop over every space on the board:
124 for y in range(HEIGHT):
125 for x in range(WIDTH):
126 # Draw the appropriate character:
127 if board[(x, y)] == WALL:
128 print(WALL, end='')
129 elif board[(x, y)] == DEAD_ROBOT:
130 print(DEAD_ROBOT, end='')
131 elif (x, y) == playerPosition:
132 print(PLAYER, end='')
133 elif (x, y) in robots:
134 print(ROBOT, end='')
135 else:
136 print(EMPTY_SPACE, end='')
137 print() # Print a newline.
138
139
140def askForPlayerMove(board, robots, playerPosition):

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected