Код: Выделить всё
#food.py
from turtle import Turtle
import random
class Food(Turtle):
def __init__(self):
super().__init__()
self.shape("square")
self.penup()
self.shapesize(stretch_len= 0.5, stretch_wid= 0.5)
self.color("navy")
self.speed("fastest")
self.refresh()
def refresh(self):
random_x = random.randint(-280, 280)
random_y = random.randint(-280, 280)
self.goto(random_x, random_y)
#main.py
is_on = True
while is_on:
screen.update()
time.sleep(0.1)
snake.move()
if snake.segment[0].distance(food) < 15:
food.refresh()
Подробнее здесь: https://stackoverflow.com/questions/758 ... hy-the-old
Мобильная версия