def draw_tile(self, window: Window, inverted: bool): board_rect = [ self.position[0], self.position[1], Tile.TILE_WIDTH, Tile.TILE_HEIGHT ] rect: pygame.Surface = pygame.Surface(self.tile_size) if self.is_open != inverted: rect.set_alpha(12) rect.fill(Tile.OPEN_TILE_COLOR) window.draw_surface(rect, self.position) if self.bug != Bug.NO_BUG: if self.bug == Bug.FAKE_BUG: bug_image = pygame.image.load( 'resources/fake_bug.gif').convert() else: bug_image = pygame.image.load( 'resources/bug.gif').convert() window.draw_surface(bug_image, self.bug_position) else: tile_image = pygame.image.load('resources/tile.gif').convert() window.draw_surface(tile_image, self.position) pygame.draw.rect(window.screen, BOARD_LIMITS_COLOR, board_rect, 1)
pos = alter_position(position=event.pos, active_bugs=on_play_bugs, win_size=window.size, height_offset=HEIGHT_OFFSET) bug_found = mouse_clicked(playing_board, pos, active_bugs=on_play_bugs) if bug_found in on_play_bugs: on_play_bugs.remove(bug_found) for bug_event in event_list: on_play_bugs = bug_event.action(playing_board, on_play_bugs) window.draw_background() window.draw_surface(text_surface, (50, 50)) if not len(on_play_bugs): bug_text_surface: pygame.Surface = window.render_text( f'No bugs left! Congratulations!') window.draw_surface(bug_text_surface, (50, 80)) elif bug_found != Bug.NO_BUG: bug_text_surface: pygame.Surface = window.render_text( f'Bug {bug_found} found!') window.draw_surface(bug_text_surface, (50, 80)) draw_tile_board(window, board=playing_board, active_bugs=on_play_bugs, height_offset=HEIGHT_OFFSET) window.update()