2023-05-18 23:18:07 +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):
|
|
|
|
def __init__(
|
|
|
|
self, world: World, vacuum: Vacuum, move_vector: Tuple[int, int]
|
|
|
|
) -> None:
|
|
|
|
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
|
|
|
|
if not self.world.accepted_move(end_x, end_y):
|
|
|
|
return
|
|
|
|
|
2023-06-15 16:46:08 +02:00
|
|
|
garbage = self.world.garbage_at(end_x, end_y)
|
|
|
|
if len(garbage) > 0:
|
|
|
|
for item in garbage:
|
2023-05-25 16:23:56 +02:00
|
|
|
if self.vacuum.get_container_filling() < 100:
|
2023-05-19 15:49:17 +02:00
|
|
|
self.vacuum.increase_container_filling()
|
2023-06-15 16:46:08 +02:00
|
|
|
self.world.delete_entities_at_Of_type(item.x, item.y, item.type)
|
2023-06-16 03:22:30 +02:00
|
|
|
self.world.dust[end_x][end_y].remove(item)
|
2023-05-18 23:18:07 +02:00
|
|
|
|
|
|
|
if self.world.is_docking_station_at(end_x, end_y):
|
|
|
|
self.vacuum.dump_trash()
|
|
|
|
|
|
|
|
self.vacuum.x = end_x
|
|
|
|
self.vacuum.y = end_y
|