Files
python_bootcamp/020/food.py
2025-07-15 15:13:04 +02:00

23 lines
586 B
Python

from turtle import Turtle, Screen
import random
class Food(Turtle):
def __init__(self, screen_x_size, screen_y_size):
super().__init__()
self.shape("square")
self.color("cyan")
self.pu()
x_limit = int((screen_x_size-20)/40)
y_limit = int((screen_y_size-20)/40)
x_pos = random.randint(-x_limit, x_limit)*20
y_pos = random.randint(-y_limit, y_limit)*20
self.teleport(x=x_pos, y=y_pos)
def get_position(self):
return self.xcor(), self.ycor()
def hide(self):
self.hideturtle()