本文整理汇总了Python中canvas.Canvas.check_black方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.check_black方法的具体用法?Python Canvas.check_black怎么用?Python Canvas.check_black使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类canvas.Canvas
的用法示例。
在下文中一共展示了Canvas.check_black方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Canvas
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import check_black [as 别名]
t1.undraw()
t2.undraw() # Un-draw game name and author name
b_start.clear() # clear start button
t_white.draw(win)
t_black.draw(win)
black_turn.draw(win)
win.setBackground('light blue')
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()
示例2: refresh
# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import check_black [as 别名]
undoList = [[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 2, 0, 0, 0],
[0, 0, 0, 2, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]
]
restart = False
# Game Starts!
while 1:
# 黑子是否可以落子
blackHasValidMove = canvas.check_black()
blackClicked = False
if blackHasValidMove:
p2 = win.getMouse()
blackClicked = False # 黑子方是否落子
if b_qt.clicked(p2): # 如果点击quit按钮
break
if b_undo.clicked(p2): # 如果点击悔棋
canvas.undo(undoList, win)
refresh()
for i in range(8):
for j in range(8):
if canvas.board[i][j].clicked(p2) and canvas.check(i, j, 2):
# update undoList