def render(self): img = draw_board(self.type_board, [d + 1 for d in self.dice], [0] * 15, 1, "empty", "empty" + ".png", surf=pygame.display.get_surface(), render=True) pygame.display.update()
def playTicTacToe(first_player="1", second_player="2"): username = user_input.ask_user_name(first_player) opponent, difficulty = user_input.init_game() if opponent == "local": opponent_name = user_input.ask_user_name(second_player) else: opponent_name = "Computer" storage.load_scores(username, opponent, difficulty) print() console.print_board() graphic_board = gui.draw_board() first_player_turn = False first_player_piece = user_input.choose_piece() second_player_piece = "O" if first_player_piece == "X" else "X" while True: first_player_turn = not first_player_turn piece = first_player_piece if first_player_turn else second_player_piece print(f"\nIt's {username if first_player_turn else opponent_name}'s turn!") if not first_player_turn and opponent == "computer": print("CPU is playing...") time.sleep(1) pos = play_cpu_turn(difficulty) else: pos = user_input.ask_user_move(piece) while not logic.is_valid_pos(pos): pos = user_input.ask_user_move(piece) console.place_piece(pos, first_player_turn, piece) gui.draw_piece(graphic_board, pos, piece) console.print_board() if logic.check_win(username, opponent_name): storage.save_scores(username, opponent, difficulty) if user_input.replay(): graphic_board.close() console.reset_board() config.player1_positions = set() config.player2_positions = set() return True else: graphic_board.close() print("Goodbye!") return False
y = int(event.pos[1] // (TILE_HEIGHT + 6)) selected_tile = False if selected_tile == (x, y) else (x, y) if event.type == pygame.KEYDOWN: if event.unicode == '\r': message = False elif event.unicode == '\x1b': if board.check_solution(): message = messages['success'] start_new_game = True else: message = messages['fail'] start_new_game = True else: if selected_tile: x, y = selected_tile try: key = int(event.unicode) if key in [n for n in range(1, 10) ] and not board.check_if_tile_locked(x, y): board.tiles[x][y] = key except ValueError: message = messages['wrong_key'] gui.draw_board(board, SCREEN, FONT, TILE_SIZE, selected_tile, WHITE, LIGHT_GREY, BLACK, GREY, DARK_GREY) if message: gui.draw_center_message(message, WHITE, FONT, BLACK, SCREEN) pygame.display.update() if start_new_game: board.new_board(get_new_board()) start_new_game = False
def drawBoard(self, openNodes, closedNodes, isFinished): draw_board(self.variables, isFinished)
def drawBoard(self, openNodes, closedNodes, isFinished): board = self.generateBoard() draw_board(board, isFinished)