while run: g.draw_grid(SCREENWIDTH, SCREENHEIGHT) draw_menu() for event in pygame.event.get(): if event.type == pygame.QUIT: run = False elif event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = pygame.mouse.get_pos() tile = g.tile_clicked(mouse_pos, SCREENWIDTH) if set_board_rect.collidepoint(mouse_pos): copy = g.copy_grid() board.set_board(g.get_board()) if not board.is_valid_board(): not_valid = font.render("Invalid Board", True, (255, 0, 0)) not_valid_rect = not_valid.get_rect() not_valid_rect.center = (SCREENWIDTH // 2, SCREENHEIGHT // 2) w.blit(not_valid, not_valid_rect) pygame.display.update() time.sleep(2) w.fill((255, 255, 255)) elif clear_board_rect.collidepoint(mouse_pos): g.clear_grid() w.fill((255, 255, 255)) g.draw_grid(SCREENWIDTH, SCREENHEIGHT) board.set_board(g.get_board()) elif reset_board_rect.collidepoint(mouse_pos):