2023-03-29 07:13:08 +02:00
|
|
|
from domain.entities.entity import Entity
|
2023-03-28 20:14:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class World:
|
|
|
|
def __init__(self, width: int, height: int):
|
|
|
|
self.width = width
|
|
|
|
self.height = height
|
2023-03-29 07:13:08 +02:00
|
|
|
self.dust = [
|
|
|
|
[[] for j in range(height)] for i in range(width)
|
|
|
|
]
|
|
|
|
self.obstacles = [
|
2023-03-28 20:14:23 +02:00
|
|
|
[[] for j in range(height)] for i in range(width)
|
|
|
|
]
|
|
|
|
|
2023-03-29 07:13:08 +02:00
|
|
|
self.vacuum = None
|
|
|
|
self.cat = None
|
|
|
|
|
2023-03-29 11:27:59 +02:00
|
|
|
def add_entity(self, entity: Entity):
|
|
|
|
if entity.type == "PEEL":
|
|
|
|
self.dust[entity.x][entity.y].append(entity)
|
|
|
|
elif entity.type == "VACUUM":
|
|
|
|
self.vacuum = entity
|
|
|
|
elif entity.type == "CAT":
|
|
|
|
self.cat = entity
|
|
|
|
self.obstacles[entity.x][entity.y].append(entity)
|
|
|
|
else:
|
|
|
|
self.obstacles[entity.x][entity.y].append(entity)
|
2023-03-28 20:14:23 +02:00
|
|
|
|
2023-03-29 07:13:08 +02:00
|
|
|
def is_obstacle_at(self, x: int, y: int) -> bool:
|
|
|
|
return bool(self.obstacles[x][y])
|