コード例 #1
0
ファイル: oxo_ui.py プロジェクト: dnnb/Mac-Python-3.X
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")
コード例 #2
0
ファイル: oxo_dialog_ui.py プロジェクト: dnnb/Mac-Python-3.X
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))
コード例 #3
0
def ev_save():
    game = cells2game()
    oxo_logic.save_game(game)