Ejemplo n.º 1
0
            canvas = Canvas(win)  # init the canvas

            logging.info('A new game starts!')

            while 1:
                # 黑子是否可以落子
                whether_black = canvas.check_black()
                if whether_black:
                    p2 = win.getMouse()

                    whether_clicked = False  # 黑子方是否落子
                    if b_qt.clicked(p2):  # 如果点击quit按钮
                        break
                    for i in range(8):
                        for j in range(8):
                            if canvas.board[i][j].clicked(p2) and canvas.check(i, j, 2):
                                canvas.click(i, j, 2)
                                logging.info('BLACK places at (%s, %s)' % (i, j))
                                canvas.piece_num[2] += 1  # 更新棋盘上两种颜色的棋子数

                                # 黑色落子,光标移动,轮到白色
                                black_turn.undraw()
                                white_turn.draw(win)

                                canvas.total_num += 1
                                refresh()
                                whether_clicked = True  # 标记为已经落子

                if not whether_black:
                    # 黑色不能落子
                    black_turn.undraw()