Return a dictionary of a new Flood It board.
()
| 86 | |
| 87 | |
| 88 | def getNewBoard(): |
| 89 | """Return a dictionary of a new Flood It board.""" |
| 90 | |
| 91 | # Keys are (x, y) tuples, values are the tile at that position. |
| 92 | board = {} |
| 93 | |
| 94 | # Create random colors for the board. |
| 95 | for x in range(BOARD_WIDTH): |
| 96 | for y in range(BOARD_HEIGHT): |
| 97 | board[(x, y)] = random.choice(TILE_TYPES) |
| 98 | |
| 99 | # Make several tiles the same as their neighbor. This creates groups |
| 100 | # of the same color/shape. |
| 101 | for i in range(BOARD_WIDTH * BOARD_HEIGHT): |
| 102 | x = random.randint(0, BOARD_WIDTH - 2) |
| 103 | y = random.randint(0, BOARD_HEIGHT - 1) |
| 104 | board[(x + 1, y)] = board[(x, y)] |
| 105 | return board |
| 106 | |
| 107 | |
| 108 | def displayBoard(board, displayMode): |