automatyczny_kelner/src/obj/Waiter.py

51 lines
1.7 KiB
Python
Raw Normal View History

import copy
from src.obj.Object import Object
class Waiter(Object):
2023-05-14 14:23:37 +02:00
def __init__(self, position, orientation, square_size, screen_size, basket=[]):
super().__init__("waiter", position, orientation, square_size, screen_size)
self.basket_size = 2
self.basket = basket
self.prev_position = copy.deepcopy(self.position)
self.prev_orientation = copy.copy(self.orientation)
2023-05-14 14:23:37 +02:00
def changeState(self, state):
self.position = copy.deepcopy(state.position)
self.orientation = copy.copy(state.orientation)
self.basket = copy.copy(state.basket)
return state
def dampState(self):
self.prev_position = copy.deepcopy(self.position)
self.prev_orientation = copy.copy(self.orientation)
def rollbackState(self):
self.position = copy.deepcopy(self.prev_position)
self.orientation = copy.copy(self.prev_orientation)
def orders_in_basket(self) -> bool:
return self.basket
def left(self):
self.orientation = (self.orientation + 1) % 4
def right(self):
self.orientation = (self.orientation - 1) % 4
def front(self):
if self.orientation % 2: # x (1 or 3)
self.position[0] += self.orientation - 2 # x (-1 or +1)
else: # y (0 or 2)
self.position[1] += self.orientation - 1 # y (-1 or +1)
def collide_test(self, obj) -> bool:
out_of_range = [
self.position[0] >= self.square_count,
self.position[1] >= self.square_count,
self.position[0] < 0,
self.position[1] < 0
]
return any(out_of_range)