gpt4 book ai didi

python - Python 3.x-Python Tkinter

转载 作者:行者123 更新时间:2023-12-03 17:49:01 26 4
gpt4 key购买 nike

我正在尝试创建一个矿工游戏,但每次都崩溃。你能帮助我吗?这是我的代码:

def refill(event):
for i in everything:
c.delete(i) # This is the 'Delete' statement
time.sleep(0.01)
global x2
global y2
for i in range(10): # This is the 'Create' statement
for i in range(10):
if random.randint(1, IRON_CHANCE) != 1:
stone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray')
everything.append(stone)
y2 += 50
if random.randint(1, IRON_CHANCE) == 1:
ironStone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray')
ironRect = c.create_rectangle(x2 + 10, y2 + 10, x2 + 40, y2 + 40, fill='ivory')
irons.append(ironRect)
everything.append(ironStone)
everything.append(ironRect)
y2 += 50
time.sleep(0.01)
x2 += 50
y2 = 0
time.sleep(0.01)

我认为问题出在“创建”状态。如果我删除该状态,
游戏工作顺利且良好。你能帮我么?

最佳答案

请注意,此声明

if random.randint(1, IRON_CHANCE) != 1:

可以等于1,并且下一个if语句不能同时等于1,因为您使用的是2个不同的数字。也许您想要其他。如果没有更完整的代码以及错误的完整引用,我们将无济于事。
            if random.randint(1, IRON_CHANCE) != 1:
stone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray')
everything.append(stone)
y2 += 50
else:
ironStone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray')
ironRect = c.create_rectangle(x2 + 10, y2 + 10, x2 + 40, y2 + 40, fill='ivory')
irons.append(ironRect)
etc

关于python - Python 3.x-Python Tkinter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47888605/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com