我正在尝试使用Python编写自己的四联游戏。我正在尝试将绘制的圆排序为2d数组。但是,当我尝试将形状对象分配给数组时,它给了我一个索引错误。我真的看不到计数器行和计数列的问题,还有其他人可以吗?顺便说一句,我的太空舱只有一个初始化程序设置x1,x2,y1,y2,take和id
from tkinter import *
from space import *
master = Tk();
w = Canvas(master, width = 600, height = 500)
w.pack()
spaceList = []
for i in range(7):
spaceList.append([0] * 6)
currentmove = 'PLAYER1'
won = False
counterrow = 0
countercolumn = 0
for i in range(0,560,80):
for j in range(0,480,80):
w.create_oval(10+i, 10+j, 90+i, 90+j)
newspace = Space(10+i, 10+j, 90+i, 90+j, False, 'EMPTY')
spaceList[counterrow][countercolumn] = newspace
countercolumn = countercolumn + 1
counterrow = counterrow + 1
while(not won):
movecol = int(input("Please select a column!"))
def move(column):
for i in spaceList:
return 0
mainloop()
答案 0 :(得分:0)
您必须重置对应列:
for i in range(0,560,80):
# add this:
countercolumn = 0
for j in range(0,480,80):
# omitted
否则它将变为7或更大,并且您会溢出。