Redesigned project architecture to be a little bit more modular #12
@ -1,4 +1,3 @@
|
||||
class Command:
|
||||
def run(self):
|
||||
raise NotImplementedError()
|
||||
|
@ -6,8 +6,9 @@ from domain.world import World
|
||||
|
||||
|
||||
class VacuumMoveCommand(Command):
|
||||
|
||||
def __init__(self, world: World, vacuum: Vacuum, move_vector: Tuple[int, int]) -> None:
|
||||
def __init__(
|
||||
self, world: World, vacuum: Vacuum, move_vector: Tuple[int, int]
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self.world = world
|
||||
self.vacuum = vacuum
|
||||
@ -18,7 +19,12 @@ class VacuumMoveCommand(Command):
|
||||
end_x = self.vacuum.x + self.dx
|
||||
end_y = self.vacuum.y + self.dy
|
||||
|
||||
if end_x > self.world.width - 1 or end_y > self.world.height - 1 or end_x < 0 or end_y < 0:
|
||||
if (
|
||||
end_x > self.world.width - 1
|
||||
or end_y > self.world.height - 1
|
||||
or end_x < 0
|
||||
or end_y < 0
|
||||
):
|
||||
return
|
||||
|
||||
if self.world.is_obstacle_at(end_x, end_y):
|
||||
|
@ -4,6 +4,6 @@ from domain.world import World
|
||||
|
||||
class Vacuum(Entity):
|
||||
def __init__(self, x: int, y: int):
|
||||
super().__init__(x, y, 'VACUUM')
|
||||
super().__init__(x, y, "VACUUM")
|
||||
self.battery = 100
|
||||
# TODO add more properties
|
||||
|
@ -5,12 +5,8 @@ class World:
|
||||
def __init__(self, width: int, height: int):
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.dust = [
|
||||
[[] for j in range(height)] for i in range(width)
|
||||
]
|
||||
self.obstacles = [
|
||||
[[] for j in range(height)] for i in range(width)
|
||||
]
|
||||
self.dust = [[[] for j in range(height)] for i in range(width)]
|
||||
self.obstacles = [[[] for j in range(height)] for i in range(width)]
|
||||
|
||||
self.vacuum = None
|
||||
self.cat = None
|
||||
|
Loading…
Reference in New Issue
Block a user