oxo_dialog_ui.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:Mac-Python-3.X 作者: L1nwatch 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号