def play_game(game): result = "" while not result: print_game(game) choice = input("Cell[1-9 or q to quit]: ") if choice.lower()[0] == "q": save = mb.askyesno("Save game", "Save game before quitting?") if save: oxo_logic.save_game(game) quit_game() else: try: cell = int(choice) - 1 if not (0 <= cell <= 8): # check range raise ValueError except ValueError: print("Choose a number between 1 and 9 or 'q' to quit ") continue try: result = oxo_logic.user_move(game, cell) except ValueError: mb.showerror("Invalid cell", "Choose an empty cell") continue if not result: result = oxo_logic.computer_move(game) if not result: continue elif result == "D": print_game(game) mb.showinfo("Result", "It's a draw") else: print_game(game) mb.showinfo("Result", "Winner is {}".format(result))
def play_game(game): result = "" while not result: print_game(game) choice = input("Cell[1-9 or q to quit]: ") if choice.lower()[0] == "q": save = input("Save game before quitting?[y/n] ") if save.lower()[0] == "y": oxo_logic.save_game(game) quit_game() else: try: cell = int(choice) - 1 if not (0 <= cell <= 8): # check range raise ValueError except ValueError: print("Choose a number between 1 and 9 or 'q' to quit ") continue try: result = oxo_logic.user_move(game, cell) except ValueError: print("Choose an empty cell ") continue if not result: result = oxo_logic.computer_move(game) if not result: continue elif result == "D": print_game(game) print("Its a draw") else: print_game(game) print("Winner is", result, "\n")
def ev_click(row, col): global game_over if game_over: mb.showerror("Game over", "Game over!") return game = cells2game() index = (3 * row) + col result = oxo_logic.user_move(game, index) game2cells(game) if not result: result = oxo_logic.computer_move(game) game2cells(game) if result == "D": mb.showinfo("Result", "It's a Draw!") game_over = True else: if result == "X" or result == "O": mb.showinfo("Result", "The winner is: {}".format(result)) game_over = True
def ev_click(row, col): global status if status["text"] == "Game Over": mb.showerror("Game over", "Game over!") return game = cells2game() index = (3 * row) + col result = oxo_logic.user_move(game, index) game2cells(game) if not result: result = oxo_logic.computer_move(game) game2cells(game) if result == "D": mb.showinfo("Result", "It's a Draw!") status["text"] = "Game Over" elif result == "X" or result == "O": mb.showinfo("Result", "The winner is: {}".format(result)) status["text"] = "Game Over"