2022-07-21 16:07:13 -05:00
|
|
|
from abc import abstractmethod
|
|
|
|
from turtle import Turtle
|
|
|
|
|
|
|
|
class BoundedTurtle(Turtle):
|
2022-07-21 16:36:45 -05:00
|
|
|
def __init__(self, speed, x_min, x_max, y_min, y_max):
|
2022-07-21 16:07:13 -05:00
|
|
|
super().__init__()
|
2022-07-21 16:36:45 -05:00
|
|
|
self.__x_min = x_min
|
|
|
|
self.__x_max = x_max
|
|
|
|
self.__y_min = y_min
|
|
|
|
self.__y_max = y_max
|
2022-07-21 16:07:13 -05:00
|
|
|
self.__speed = speed
|
|
|
|
|
2022-07-21 16:36:45 -05:00
|
|
|
def out_of_bounds(self):
|
2022-07-26 14:12:41 -05:00
|
|
|
x_pos, y_pos = self.position()
|
2022-07-21 16:07:13 -05:00
|
|
|
out = False
|
2022-07-26 14:12:41 -05:00
|
|
|
if x_pos < self.__x_min or x_pos > self.__x_max:
|
2022-07-21 16:07:13 -05:00
|
|
|
out = True
|
2022-07-26 14:12:41 -05:00
|
|
|
if y_pos < self.__y_min or y_pos > self.__y_max:
|
2022-07-21 16:07:13 -05:00
|
|
|
out = True
|
|
|
|
return out
|
|
|
|
|
2022-07-21 16:36:45 -05:00
|
|
|
def below_bottom_bound(self):
|
2022-07-21 16:07:13 -05:00
|
|
|
x_pos, y_pos = self.position()
|
|
|
|
out = False
|
2022-07-26 14:12:41 -05:00
|
|
|
if y_pos < self.__y_min:
|
2022-07-21 16:07:13 -05:00
|
|
|
out = True
|
|
|
|
return out
|
|
|
|
|
2022-07-21 16:36:45 -05:00
|
|
|
def get_speed(self):
|
2022-07-21 16:07:13 -05:00
|
|
|
return self.__speed
|
|
|
|
|
2022-07-21 16:36:45 -05:00
|
|
|
def get_x_min(self):
|
2022-07-26 14:12:41 -05:00
|
|
|
return self.__x_min
|
2022-07-21 16:07:13 -05:00
|
|
|
|
2022-07-28 13:33:12 -05:00
|
|
|
def get_x_max(self):
|
2022-07-26 14:12:41 -05:00
|
|
|
return self.__x_max
|
2022-07-21 16:07:13 -05:00
|
|
|
|
2022-07-26 14:12:41 -05:00
|
|
|
def get_y_min(self):
|
|
|
|
return self.__y_min
|
2022-07-21 16:07:13 -05:00
|
|
|
|
2022-07-26 14:12:41 -05:00
|
|
|
def get_y_max(self):
|
|
|
|
return self.__y_max
|
2022-07-21 16:07:13 -05:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def remove(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def move(self):
|
|
|
|
pass
|