Open BrowsingGuest opened 6 hours ago
class Entities:
def __init__(self):
self.solid = {}
self.non_solid = {}
def __getitem__(self, key):
return self.entities[key]
def __setitem__(self, key, value):
if value.solid:
self.solid[value.position] = value
else:
self.non_solid[value.position] = value
def __iter__(self):
return itertools.chain(self.solid.values(), self.non_solid.values())
self.entities = Entities()
self.entities += [TalkingMonster(self) for x in range(7)]
for entity in self.entities[Coordinates(1, 1)]:
print(entity)
self.entities[Coordinates(1, 1)] += [TalkingMonster(self)]
for entity in self.entities:
print(entity)
for entity in self.entitites.solid:
print(entity)
for entity in self.entities.non_solid:
print(entity)
Tohle jsem nevymyslel dobře. Pokud si Entita změní self.position, tak se to v Entities nepromítne. Musíme to vymyslet lépe.
Predelat do class nebo do seznamu