Операционная система Windows 10
Python version 3.8.5
среда разработки Visual studio 2019
Pip List
{
urlib3(1.25.10)
requests(2.24.0)
pyRect(0.1.4)
pip(20.2.3)
pillow(7.2.0)
chardet(3.0.4)
certifi(2020.6.20)
idna(2.20)
turtle
time
}
ошибка при запуске:
Traceback (most recent call last):
File "C:\Users\rafes\source\repos\Snake\Snake\Snake.py", line 63, in <module>
move()
File "C:\Users\rafes\source\repos\Snake\Snake\Snake.py", line 35, in move
if head.direction == "up":
AttributeError: 'Turtle' object has no attribute 'direction'
Для продолжения нажмите любую клавишу . . .
Python version 3.8.5
среда разработки Visual studio 2019
Pip List
{
urlib3(1.25.10)
requests(2.24.0)
pyRect(0.1.4)
pip(20.2.3)
pillow(7.2.0)
chardet(3.0.4)
certifi(2020.6.20)
idna(2.20)
turtle
time
}
ошибка при запуске:
Traceback (most recent call last):
File "C:\Users\rafes\source\repos\Snake\Snake\Snake.py", line 63, in <module>
move()
File "C:\Users\rafes\source\repos\Snake\Snake\Snake.py", line 35, in move
if head.direction == "up":
AttributeError: 'Turtle' object has no attribute 'direction'
Для продолжения нажмите любую клавишу . . .
Код:
import turtle
import time
delay = 0.1
Window = turtle.Screen()
Window.title("Snake")
Window.bgcolor("green")
Window.setup(width=800,height=600)
Window.cv._rootwindow.resizable(False, False)
Window.tracer(0)
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("white")
head.penup()
head.goto(0,0)
def go_up():
head.direction = "up"
def go_down():
head.direction = "down"
def go_left():
head.direction = "left"
def go_right():
head.direction = "right"
def move():
if head.direction == "up":
y = head.ycor()
head.sety(y + 20)
if head.direction == "down":
y = head.ycor()
head.sety(y - 20)
if head.direction == "left":
x = head.xcor()
head.setx(x - 20)
if head.direction == "right":
x = head.xcor()
head.setx(x + 20)
Window.listen()
Window.onkeypress(go_up , "w")
Window.onkeypress(go_down , "s")
Window.onkeypress(go_left , "a")
Window.onkeypress(go_right , "d")
while True:
Window.update()
move()
time.sleep(delay)
Window.mainloop()