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)
|
|
|
|
]
|
|
|
|
self.entities = []
|
|
|
|
|
2023-03-29 07:13:08 +02:00
|
|
|
self.vacuum = None
|
|
|
|
self.cat = None
|
|
|
|
|
|
|
|
# move: update position from (start_x, start_y) to (end_x, end_y)
|
|
|
|
# def move(self, entity: Entity, end_x: int, end_y: int):
|
|
|
|
# # no change
|
|
|
|
# if entity.x == end_x and entity.y == end_y:
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
# # check if object moves beyond border
|
|
|
|
# if end_x > self.width - 1 or end_y > self.height - 1 or end_x < 0 or end_y < 0:
|
|
|
|
# print("Cannot move object beyond board")
|
|
|
|
# return
|
|
|
|
#
|
|
|
|
# # check if destination is empty
|
|
|
|
# # if self.is_obstacle_at(end_x, end_y):
|
|
|
|
# # print(
|
|
|
|
# # f"Cannot move object to ({end_x}, {end_y}): position already occupied"
|
|
|
|
# # )
|
|
|
|
# # return
|
|
|
|
#
|
|
|
|
# # change position in array
|
|
|
|
# self.grid[entity.x][entity.y].remove(entity)
|
|
|
|
# self.grid[end_x][end_y].append(entity)
|
|
|
|
# entity.x = end_x
|
|
|
|
# entity.y = end_y
|
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])
|