我一直试图通过让消息框出现来检测获胜者,我正在考虑将所有被销毁的作品附加到列表中,然后如果国王在那里,那么检测到获胜,我正在努力解决是否是类GUIKing或附加到列表中的作品的图像。
def destroy_piece(self, piece):
""" Removes piece from the canvans and click-handler
automatily called by move_piece
"""
img1=piece.get_img_int(0)
img2=piece.get_img_int(1)
del self._on_clicks[str(img1)]
del self._on_clicks[str(img2)]
self.delete(piece.get_img_int(0))
self.delete(piece.get_img_int(1))
self.destroyed_pieces = []
self.destroyed_pieces.append(piece)发布于 2020-12-14 02:58:18
该列表应该包含一个对象,因此应该使用GUIKing类实例。但这取决于你如何在整个程序中做到这一点。你必须保持它的一致性,并且始终使用对象/类。这个比较好。
但为了快速修复,您可以使用以下代码:
def destroy_piece(self, piece):
""" Removes piece from the canvans and click-handler
automatily called by move_piece
"""
img1=piece.get_img_int(0)
img2=piece.get_img_int(1)
del self._on_clicks[str(img1)]
del self._on_clicks[str(img2)]
self.delete(piece.get_img_int(0))
self.delete(piece.get_img_int(1))
## self.destroyed_pieces = [] ## move this in the class __init__
self.destroyed_pieces.append(piece)
##for elem in self.destroyed_pieces: ## remove this unneccessary line
if "bk.png" or "wk.png" in self.destroyed_pieces:
messagebox.showinfo("WINNER")https://stackoverflow.com/questions/65279336
复制相似问题