每当我尝试运行脚本时,它都会停止工作
我目前正在制作PY游戏,而Python每次都停止工作,但我不确定为什么。
from turtle import Turtle, Screen
screen = Screen()
screen.setup(600, 600)
screen.bgcolor('black')
screen.title('Snake Game')
turtles = []
y = 0
x = 0
for _ in range(3):
turtle = Turtle('square')
turtle.color('white')
turtle.penup()
turtle.goto(x, y)
x -= 20
game_is_on = True
while game_is_on:
for seg in turtles:
seg.forward(20)
I am currently making a py game and python stops working every time, but I'm not sure why.
from turtle import Turtle, Screen
screen = Screen()
screen.setup(600, 600)
screen.bgcolor('black')
screen.title('Snake Game')
turtles = []
y = 0
x = 0
for _ in range(3):
turtle = Turtle('square')
turtle.color('white')
turtle.penup()
turtle.goto(x, y)
x -= 20
game_is_on = True
while game_is_on:
for seg in turtles:
seg.forward(20)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经忘记将每只乌龟添加到
Turtles
列表中。您需要做的就是将乌龟添加到for循环中。这是代码:
You have forgotten to add each turtle to the
turtles
list. All you need to do is append the turtle in the for loop.Here is the code: