#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()
< /code>
Wenn die Schlange (es gibt eine Schlange, die aus drei Schildkröten (quadratisch) das Essen berührt (Abstand
Wenn die Schlange das Essen berührt, weiß ich, warum das neue Essen auftaucht, aber warum das alte Essen verschwindet? ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Die Unity -Episode endet nicht, auch wenn das Ziel oder die Wand berührt wird
by Anonymous » » in C# - 0 Replies
- 14 Views
-
Last post by Anonymous
-
-
-
Fügen Sie Element zum Menü hinzu, das beim Klicken auf den Kontakt auftaucht
by Anonymous » » in Android - 0 Replies
- 0 Views
-
Last post by Anonymous
-