Game Development Reference
In-Depth Information
| | | | | | | | |
| X | X | X | X | X | X | X | X |
| | | | | | | | |
+---+---+---+---+---+---+---+---+
| | | | | | | | |
| X | X | X | X | X | X | X | X |
| | | | | | | | |
+---+---+---+---+---+---+---+---+
| | | | | | | | |
| X | X | X | X | X | X | X | X |
| | | | | | | | |
+---+---+---+---+---+---+---+---+
| | | | | | | | |
| X | X | X | X | X | X | X | X |
| | | | | | | | |
+---+---+---+---+---+---+---+---+
| | | | | | | | |
| X | X | X | X | X | X | X | X |
| | | | | | | | |
+---+---+---+---+---+---+---+---+
| | | | | | | | |
| X | X | X | X | X | X | X | X |
| | | | | | | | |
+---+---+---+---+---+---+---+---+
Resetting the Game Board
An important thing to remember is that the coordinates that we print out to the player are
from 1 to 8, but the indexes in the board data structure are from 0 to 7.
23. def resetBoard(board):
24. # Blanks out the board it is passed, except for the
original starting position.
25. for x in range(8):
26. for y in range(8):
27. board[x][y] = ' '
Here we use a loop inside a loop to set the board data structure to be all blanks. We will
call the resetBoard() function whenever we start a new game and want to remove the
tiles from a previous game.
Setting Up the Starting Pieces
29. # Starting pieces:
30. board[3][3] = 'X'
31. board[3][4] = 'O'
32. board[4][3] = 'O'
33. board[4][4] = 'X'
Search WWH ::




Custom Search