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

Function displayBoard

src/gamesbyexample/hexapawn.py:123–156  ·  view source on GitHub ↗

Display the board on the screen.

(board)

Source from the content-addressed store, hash-verified

121
122
123def displayBoard(board):
124 """Display the board on the screen."""
125 # Print the letter labels across the top:
126 print(' ', end='') # Print the indentation for the letter labels.
127 for x in range(board[WIDTH]):
128 print(' ', getNthLetter(x), ' ', sep='', end='')
129 print() # Print a newline.
130
131 for y in range(board[HEIGHT]):
132 # Print the horizontal border:
133 print(' ', end='') # Print the indentation.
134 for x in range(board[WIDTH]):
135 print('+---', end='')
136 print('+')
137
138 # Print the number labels on the left side:
139 print(str(y + 1).rjust(2) + ' ', end='')
140
141 # Print the board spaces:
142 for x in range(board[WIDTH]):
143 print('| ' + board[(x, y)] + ' ', end='')
144 print('|', str(y + 1).ljust(2))
145
146 # Print the last horizontal border at the very bottom:
147 print(' ', end='') # Print the indentation.
148 for x in range(board[WIDTH]):
149 print('+---', end='')
150 print('+')
151
152 # Print the letter labels across the bottom:
153 print(' ', end='') # Print the indentation for the letter labels.
154 for x in range(board[WIDTH]):
155 print(' ', chr(x + 65), ' ', sep='', end='')
156 print() # Print a newline.
157
158
159def doPlayerMove(player, board):

Callers 1

mainFunction · 0.70

Calls 1

getNthLetterFunction · 0.85

Tested by

no test coverage detected