diff --git a/gui/colors.py b/gui/colors.py index 1779189..44c6aeb 100644 --- a/gui/colors.py +++ b/gui/colors.py @@ -1,11 +1,12 @@ +# colors.py +# Contains color definitions in the form of tuples (length 3 -> RGB representation) + BLACK = (0, 0, 0) WHITE = (255, 255, 255) -RED = (255, 94, 88) # (250, 0, 0) +RED = (255, 94, 88) RED_HIGHLIGHT = (255, 219, 212) -AVAILABLE_MOVE_1 = (255, 255, 223) # Yellow -AVAILABLE_MOVE_2 = (255, 255, 255) # Yellow GREEN = (0, 200, 0) -BLUE = (59, 214, 255) # (0, 0, 250) +BLUE = (59, 214, 255) YELLOW = (0, 250, 250) BRIGHT_RED = (255, 0, 0) diff --git a/gui/gui_app.py b/gui/gui_app.py index fe674a8..01e3ff5 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -1,3 +1,5 @@ +from itertools import cycle, chain + from gui.gui_board import * @@ -6,32 +8,45 @@ def __init__(self): super(Gui, self).__init__() self.board = UltimateBoard() self.on_cell_clicked = self.subcell_clicked + self.allowed_cells = set() def subcell_clicked(self, x, y, w, h, board, move): - # todo check if the cell that is clicked is also allowed to be clicked else display warning!!!! # do not provide player just yet, only do so when we are sure we can click the cell - cell = Cell(x, y, w, h, None, board_idx=board, cell_idx=move) # todo fix this *-1 + cell = Cell(x, y, w, h, player=None, board_idx=board, cell_idx=move) if cell in self.clicked_cells: # if cell already clicked -> do nothing return + if cell not in self.allowed_cells: + return # todo raise warning or display text + cell.player = self.board.playerJustMoved * -1 self.clicked_cells.add(cell) self.board.make_move(move, board) print(board, move) print(self.board) + self.allowed_cells = self.find_allowed_cells() + + def find_allowed_cells(self): + allowed_cells = set() # clear currently allowed moves - def draw_allowed_moves(self, color): moves = self.board.get_moves() for board, move in moves: for cell in self.all_cells: if cell.board_idx == board and cell.cell_idx == move: - pygame.draw.rect(self.gameDisplay, color, - (cell.pos_x, cell.pos_y, cell.width, cell.height)) + allowed_cells.add(cell) + + return allowed_cells + + def draw_allowed_moves(self, color): + for cell in self.allowed_cells: + pygame.draw.rect(self.gameDisplay, color, + (cell.pos_x, cell.pos_y, cell.width, cell.height)) def game_loop(self): - highlight = AVAILABLE_MOVE_1 - frames = 0 + # set up an endless cycle of B values (rgB) for highlighting moves + highlight_range = [i for i in range(140, 201, 2)] + brightness_iter = cycle(chain(highlight_range, reversed(highlight_range))) while True: for event in pygame.event.get(): @@ -39,17 +54,20 @@ def game_loop(self): if event.type == pygame.QUIT: self.quit_game() - if frames == 30: - highlight = AVAILABLE_MOVE_1 if highlight == AVAILABLE_MOVE_2 else AVAILABLE_MOVE_2 - frames = 0 + brightness = next(brightness_iter) + highlight = (255, 255, brightness) # yellow highlight used to accent available moves self.gameDisplay.fill(WHITE) self.draw_main_grid() + + # todo check for game end here as well. Mind not have allowed cells because game is over + if not self.allowed_cells: + self.allowed_cells = self.find_allowed_cells() + self.draw_clicked_cells() self.draw_allowed_moves(highlight) pygame.display.update() self.clock.tick(60) - frames += 1 if __name__ == '__main__':