2023-03-29 11:27:59 +02:00
|
|
|
from typing import Tuple
|
|
|
|
|
|
|
|
from domain.commands.command import Command
|
|
|
|
from domain.entities.vacuum import Vacuum
|
|
|
|
from domain.world import World
|
|
|
|
|
|
|
|
|
|
|
|
class VacuumMoveCommand(Command):
|
2023-03-30 18:27:51 +02:00
|
|
|
def __init__(
|
|
|
|
self, world: World, vacuum: Vacuum, move_vector: Tuple[int, int]
|
|
|
|
) -> None:
|
2023-03-29 11:27:59 +02:00
|
|
|
super().__init__()
|
|
|
|
self.world = world
|
|
|
|
self.vacuum = vacuum
|
|
|
|
self.dx = move_vector[0]
|
|
|
|
self.dy = move_vector[1]
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
end_x = self.vacuum.x + self.dx
|
|
|
|
end_y = self.vacuum.y + self.dy
|
2023-04-20 03:38:55 +02:00
|
|
|
if not self.world.accepted_move(end_x, end_y):
|
2023-03-29 11:27:59 +02:00
|
|
|
return
|
|
|
|
|
2023-04-10 18:43:16 +02:00
|
|
|
if self.world.is_garbage_at(end_x, end_y):
|
2023-04-14 00:25:35 +02:00
|
|
|
if self.vacuum.get_container_filling() < 100:
|
|
|
|
self.vacuum.increase_container_filling()
|
|
|
|
self.world.dust[end_x][end_y].pop()
|
2023-04-10 18:43:16 +02:00
|
|
|
|
2023-04-13 19:04:57 +02:00
|
|
|
if self.world.is_docking_station_at(end_x, end_y):
|
|
|
|
self.vacuum.dump_trash()
|
|
|
|
|
2023-03-29 11:27:59 +02:00
|
|
|
self.vacuum.x = end_x
|
|
|
|
self.vacuum.y = end_y
|