【发布时间】:2011-10-08 02:59:28
【问题描述】:
我正在为大学开发一个 Python 跳棋游戏。我使用 tk 绘制了棋盘,但我似乎无法实现棋子的移动功能。如果有人在我的代码中看到任何错误,或者可以提供帮助,我将不胜感激。这是完整的来源。提前致谢。
我知道这会画出棋子。我不知道如何重绘这些片段,而不删除其他片段。我在网上查看了移动功能,并尝试了有效的简单测试,但我无法在我的代码中使用它。
我知道递归,但是,在我实现更多功能之前,我需要基本功能才能工作,即在屏幕上实际移动一块。
lst2 = []
#counter variable
i=0
#board variable is what stores the X/O/- values.
# It's a 2D list. We iterate over it, looking to see
# if there is a value that is X or O. If so, we draw
# text to the screen in the appropriate spot (based on
# i and j.
while i < len(board):
j=0
while j < len(board[i]):
if board[i][j] == 2:
lst2.append(canvas.create_oval((i+1)*width + width/2 + 15,
(j+1)*height + height/2 +15,(i+1)*width + width/2 - 15,
(j+1)*width + width/2 - 15, fill="Red",outline='Black'))
elif board[i][j] == 4:
lst2.append(canvas.create_oval((i+1)*width + width/2 + 15,
(j+1)*height + height/2 +15,(i+1)*width + width/2 - 15,
(j+1)*width + width/2 - 15, fill="Red",outline='Black'))
elif board[i][j] == 1:
lst2.append(canvas.create_oval((i+1)*width + width/2 + 15,
(j+1)*height + height/2 +15,(i+1)*width + width/2 - 15,
(j+1)*width + width/2 - 15, fill="Black",outline='Black'))
elif board[i][j] == 3:
lst2.append(canvas.create_oval((i+1)*width + width/2 + 15,
(j+1)*height + height/2 +15,(i+1)*width + width/2 - 15,
(j+1)*width + width/2 - 15, fill="Black",outline='Black'))
j+=1
i+=1
【问题讨论】:
-
这不是问题。您不只是转储整个程序并寻求帮助。你能告诉我们你遇到的问题吗?如果有的话,请将您的代码段缩小到与移动一块相关的部分,因为我没有时间全部筛选。
-
@Tim Post,至少给他一两天时间来编辑问题以解决它?
-
@Tim Post,我反对突然关闭而没有给他时间回复,我raised this for discussion on MSO。
-
关闭后可以编辑问题。如果它得到修复,请将其标记为重新打开。
-
@smci:我不明白你的意思。那条评论是五年半前的,我发表评论后唯一的编辑就是你刚刚做出的编辑。在其中一次编辑后,我也删除了我的反对票,尽管我不知道是哪个。
标签: python tkinter tk python-2.7