38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from enum import Enum
|
|
from entity import Character, Entity, Item
|
|
|
|
class TileType(Enum):
|
|
WALL = 1
|
|
AIR = 2
|
|
|
|
class Floor:
|
|
def __init__(self, width, height):
|
|
self.width = width
|
|
self.height = height
|
|
self.grid = [[TileType.AIR] * height] * width
|
|
self.entities = {
|
|
Character: {},
|
|
Item: {}
|
|
}
|
|
|
|
def get_tile(self, x, y):
|
|
return self.grid[x][y]
|
|
|
|
def add_entity(self, x, y, entity: Entity) -> bool:
|
|
if isinstance(entity, Character):
|
|
if (x, y) in self.entities[Character]:
|
|
return False
|
|
else:
|
|
self.entities[Character][(x, y)] = entity
|
|
return True
|
|
elif isinstance(entity, Item):
|
|
if (x, y) not in self.entities[Item]:
|
|
self.entities[Item][(x,y)] = []
|
|
self.entities[Item][(x,y)].append(entity)
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def pop_character(self, x, y) -> Character | None:
|
|
if (x, y) in self.entities[Character]:
|
|
return self.entities[Character].pop((x, y)) |