[Python] when the snake touch the food, i know why the new food comes up but why the old food...

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    #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()



    when the snake(there is a snake which made of three turtles(square)) touch the food(distance < 15), i know why the new food comes up but why the old food disappears? there is not function that erase the old food

    Continue reading...

Compartilhe esta Página