76 lines
3.0 KiB
Python
76 lines
3.0 KiB
Python
import definitions
|
|
|
|
|
|
class Cart:
|
|
def __init__(self, direction, x, y):
|
|
self.direction = direction # w którą stronę patrzy, zgodnie ze wskazówkami zegara (1 -: godzina 12, 2 : godzina 3, 3 : godzina 6, 4 : godzina 9)
|
|
self.x = x
|
|
self.y = y
|
|
|
|
def get_direction(self):
|
|
return self.direction
|
|
|
|
def set_direction(self, direction):
|
|
self.direction = direction
|
|
|
|
def get_x(self):
|
|
return self.x
|
|
|
|
def set_x(self, x):
|
|
self.x = x
|
|
|
|
def get_y(self):
|
|
return self.y
|
|
|
|
def set_y(self, y):
|
|
self.y = y
|
|
|
|
def is_move_allowed(self,
|
|
cart_rect): # sprawdza czy dany ruch, który chce wykonać wózek jest możliwy, zwraca prawdę lub fałsz
|
|
if self.direction == definitions.CART_DIRECTION_EAST and cart_rect.x + definitions.BLOCK_SIZE < definitions.WIDTH_MAP:
|
|
return True
|
|
elif self.direction == definitions.CART_DIRECTION_SOUTH and cart_rect.y - definitions.BLOCK_SIZE > 0:
|
|
return True
|
|
elif self.direction == definitions.CART_DIRECTION_NORTH and cart_rect.y + definitions.BLOCK_SIZE < definitions.HEIGHT_MAP:
|
|
return True
|
|
elif self.direction == definitions.CART_DIRECTION_WEST and cart_rect.x - definitions.BLOCK_SIZE > 0:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
@staticmethod
|
|
def is_move_allowed_succ(
|
|
node): # sprawdza czy dany ruch, który chce wykonać wózek jest możliwy, zwraca pozycje po wykonaniu ruchu, wersja node
|
|
if node.get_direction() == definitions.CART_DIRECTION_EAST and node.get_x() * definitions.BLOCK_SIZE + definitions.BLOCK_SIZE < definitions.WIDTH_MAP:
|
|
return "x + 1"
|
|
elif node.get_direction() == definitions.CART_DIRECTION_NORTH and node.get_y() * definitions.BLOCK_SIZE - definitions.BLOCK_SIZE > 0:
|
|
return "y - 1"
|
|
elif node.get_direction() == definitions.CART_DIRECTION_SOUTH and node.get_y() * definitions.BLOCK_SIZE + definitions.BLOCK_SIZE < definitions.HEIGHT_MAP:
|
|
return "y + 1"
|
|
elif node.get_direction() == definitions.CART_DIRECTION_WEST and node.get_x() * definitions.BLOCK_SIZE - definitions.BLOCK_SIZE > 0:
|
|
return "x - 1"
|
|
else:
|
|
return False
|
|
|
|
def move(self):
|
|
if self.direction == definitions.CART_DIRECTION_EAST:
|
|
self.x = self.x + definitions.BLOCK_SIZE
|
|
elif self.direction == definitions.CART_DIRECTION_NORTH:
|
|
self.y = self.y + definitions.BLOCK_SIZE
|
|
elif self.direction == definitions.CART_DIRECTION_SOUTH:
|
|
self.y = self.y - definitions.BLOCK_SIZE
|
|
elif self.direction == definitions.CART_DIRECTION_WEST:
|
|
self.x = self.x - definitions.BLOCK_SIZE
|
|
|
|
def rotate_right(self):
|
|
if self.direction == 1:
|
|
self.direction = 4
|
|
else:
|
|
self.direction = self.direction - 1
|
|
|
|
def rotate_left(self):
|
|
if self.direction == 4:
|
|
self.direction = 1
|
|
else:
|
|
self.direction = self.direction + 1
|