Beispiel #1
0
def button_m():
    # 人机对战菜单
    c_s()
    Chess.new()
    draw()
    global auto
    auto = threading.Thread(target=detector)
    auto.start()
    canvas.delete('ButtonMain')
    # 新局
    open_gs_button = tk.Button(root, text='新局', command=new)
    canvas.create_window(720,
                         100,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=open_gs_button,
                         tags='ButtonM')
    # 悔棋
    regret_button = tk.Button(root, text='悔棋', command=regret)
    canvas.create_window(720,
                         190,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=regret_button,
                         tags='ButtonM')
    # 提示
    tips_button = tk.Button(root, text='提示', command=tips)
    canvas.create_window(720,
                         280,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=tips_button,
                         tags='ButtonM')

    # 保存棋谱
    save_gbs_button = tk.Button(root, text='保存棋谱', command=save_gbs)
    canvas.create_window(720,
                         370,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=save_gbs_button,
                         tags='ButtonM')
    # 返回主菜单
    return_button = tk.Button(root, text='返回主菜单', command=button_main)
    canvas.create_window(720,
                         460,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=return_button,
                         tags='ButtonM')
Beispiel #2
0
def button_score():
    # 初始化
    c_s()
    Chess.new()
    draw()
    canvas.delete('ButtonMain')
    # 新局
    open_gs_button = tk.Button(root, text='新局', command=new)
    canvas.create_window(720,
                         100,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=open_gs_button,
                         tags='ButtonScore')

    # 载入棋谱
    open_gs_button = tk.Button(root, text='载入棋谱', command=open_gs)
    canvas.create_window(720,
                         190,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=open_gs_button,
                         tags='ButtonScore')
    # 悔棋
    regret_button = tk.Button(root, text='悔棋', command=regret)
    canvas.create_window(720,
                         280,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=regret_button,
                         tags='ButtonScore')
    # 保存棋谱
    save_gbs_button = tk.Button(root, text='保存棋谱', command=save_gbs)
    canvas.create_window(720,
                         370,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=save_gbs_button,
                         tags='ButtonScore')
    # 返回主菜单
    return_button = tk.Button(root, text='返回主菜单', command=button_main)
    canvas.create_window(720,
                         500,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=return_button,
                         tags='ButtonScore')
Beispiel #3
0
def score_mode(step_dict):
    canvas.delete('ButtonScore')
    temp_dict = step_dict.copy()
    Chess.new()
    dicttoChees(step_dict)
    draw()

    def forward():
        # 下一步
        if len(temp_dict) != len(step_dict):
            temp_dict.update(
                {len(temp_dict) + 1: step_dict[len(temp_dict) + 1]})
            dicttoChees(temp_dict)
            draw()

    def retreat():
        # 上一步
        if len(temp_dict) != 0:
            temp_dict.popitem()
            dicttoChees(temp_dict)
            draw()

    def play():
        def stop():
            thread_stop.stop_thread(t)
            regret_button = tk.Button(root, text='⏩', command=play)
            canvas.create_window(767,
                                 370,
                                 anchor='nw',
                                 width=30,
                                 height=30,
                                 window=regret_button,
                                 tags='ScoreMode')

        regret_button = tk.Button(root, text='⏸', command=stop)
        canvas.create_window(767,
                             370,
                             anchor='nw',
                             width=30,
                             height=30,
                             window=regret_button,
                             tags='ScoreMode')
        nonlocal temp_dict
        if len(temp_dict) == len(step_dict):
            temp_dict = {}

        def play_t():
            for i in range(len(step_dict) - len(temp_dict)):
                forward()
                time.sleep(1)
            regret_button = tk.Button(root, text='⏩', command=play)
            canvas.create_window(767,
                                 370,
                                 anchor='nw',
                                 width=30,
                                 height=30,
                                 window=regret_button,
                                 tags='ScoreMode')

        t = threading.Thread(target=play_t)
        t.start()

    regret_button = tk.Button(root, text='◀', command=retreat)
    canvas.create_window(720,
                         370,
                         anchor='nw',
                         width=30,
                         height=30,
                         window=regret_button,
                         tags='ScoreMode')

    regret_button = tk.Button(root, text='⏩', command=play)
    canvas.create_window(767,
                         370,
                         anchor='nw',
                         width=30,
                         height=30,
                         window=regret_button,
                         tags='ScoreMode')

    regret_button = tk.Button(root, text='▶', command=forward)
    canvas.create_window(810,
                         370,
                         anchor='nw',
                         width=30,
                         height=30,
                         window=regret_button,
                         tags='ScoreMode')

    # 返回主菜单
    return_button = tk.Button(root, text='返回主菜单', command=button_main)
    canvas.create_window(720,
                         500,
                         anchor='nw',
                         width=120,
                         height=50,
                         window=return_button,
                         tags='ButtonScore')
Beispiel #4
0
def new():
    # 新局
    if tkinter.messagebox.askyesno('重新开始', '要重新开始游戏吗?'):
        Chess.new()
        draw()