Remove BoundDestination Object

New Variable 'var_can_be_bound'
Observations adjusted accordingly
This commit is contained in:
Steffen Illium
2023-10-12 17:14:32 +02:00
parent e326a95bf4
commit f5c6317158
22 changed files with 98 additions and 110 deletions

View File

@@ -56,6 +56,7 @@ class Entity(EnvObject, abc.ABC):
return last_x - curr_x, last_y - curr_y
def destroy(self):
if
valid = self._collection.remove_item(self)
for observer in self.observers:
observer.notify_del_entity(self)
@@ -73,10 +74,17 @@ class Entity(EnvObject, abc.ABC):
return valid
return not_same_tile
def __init__(self, tile, **kwargs):
def __init__(self, tile, bind_to=None, **kwargs):
super().__init__(**kwargs)
self._status = None
self._tile = tile
if bind_to:
try:
self.bind_to(bind_to)
except AttributeError:
print(f'Objects of {self.__class__.__name__} can not be bound to other entities.')
exit()
assert tile.enter(self, spawn=True), "Positions was not valid!"
def summarize_state(self) -> dict:

View File

@@ -9,10 +9,16 @@ class BoundEntityMixin:
@property
def name(self):
return f'{self.__class__.__name__}({self.bound_entity.name})'
if self.bound_entity:
return f'{self.__class__.__name__}({self.bound_entity.name})'
else:
print()
def belongs_to_entity(self, entity):
return entity == self.bound_entity
def bind_to(self, entity):
self._bound_entity = entity
def unbind(self):
self._bound_entity = None

View File

@@ -91,6 +91,13 @@ class EnvObject(Object):
except AttributeError:
return False
@property
def var_can_be_bound(self):
try:
return self._collection.var_can_be_bound or False
except AttributeError:
return False
@property
def var_can_move(self):
try: