Dodanie funkcji dla obrotu w lewo i w prawo

This commit is contained in:
andrzej 2020-04-23 20:55:51 +02:00
parent 716b4f0577
commit 976d285e4b
2 changed files with 26 additions and 2 deletions

View File

@ -1,5 +1,5 @@
from warehouse import Coordinates, Tile, Pack
from attributes import PackStatus
from attributes import PackStatus, TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS
class Agent:
def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
@ -27,6 +27,15 @@ class Agent:
else:
self.x = next_coords.x
self.y = next_coords.y
def turn_left(self):
new_direction = TURN_LEFT_DIRECTIONS.get(self.direction, self.direction)
self.direction = new_direction
def turn_right(self):
new_direction = TURN_RIGHT_DIRECTIONS.get(self.direction, self.direction)
self.direction = new_direction
def move(self):
next_coords = self.get_next_move_coordinates()
can_move = self.check_if_can_move(next_coords)

View File

@ -26,3 +26,18 @@ COLORS = {
'lightgreen': (70, 238, 70),
'red': (255, 0, 0)
}
TURN_LEFT_DIRECTIONS = {
"left": "down",
"down": "right",
"right": "up",
"up": "left"
}
TURN_RIGHT_DIRECTIONS = {
"left": "up",
"up": "right",
"right": "down",
"down": "left"
}