大家来看看我的代码有什么问题?画布窗口老闪退
gamebase.py文件
from turtle import *
def square(x,y,size,color_name):
up()
goto(x,y)
down()
color(color_name)
begin_fill()
forward(size)
left(90)
forward(size)
left(90)
forward(size)
left(90)
forward(size)
left(90)
end_fill()
snake.py文件
from turtle import *
from gamebase import square
from random import randrange
snake=[[0,0],[10,0],[20,0],[30,0],[40.0],[50,0]]
apple_x=randrange(-200,200)
apple_y=randrange(-200,200)
def gameLoop():
global apple_x,apple_y
for n in range(len(snake)):
square(snake[n][0],snake[n][1],10,"black")
square(apple_x,apple_y,10,"red")
update()
setup(420,420,0,0)
hideturtle()
tracer(False)
gameLoop()
done()
兄弟们就是这个了,我看终端他说列表索引超出范围?什么东东?
这个写作器好奇怪
窗口闪退的话……最后要加个done()