Fight other entities while bumping them, without any weapon

This commit is contained in:
Yohann D'ANELLO
2020-11-11 01:04:30 +01:00
parent 9909b12501
commit c5e6459d37
3 changed files with 9 additions and 14 deletions

View File

@ -34,16 +34,18 @@ class Player(FightingEntity):
self.current_xp += xp
self.level_up()
def fight(self) -> bool:
def check_move(self, y: int, x: int, move_if_possible: bool = False) \
-> bool:
"""
Fight all f
If the player tries to move but a fighting entity is there,
the player fights this entity.
It rewards some XP if it is dead.
"""
one_fight = False
for entity in self.map.entities:
if entity != self and isinstance(entity, FightingEntity) and\
self.distance_squared(entity) <= 1:
if entity.y == y and entity.x == x and \
isinstance(entity, FightingEntity):
self.hit(entity)
one_fight = True
if entity.dead:
self.add_xp(randint(3, 7))
return one_fight
return True
return super().check_move(y, x, move_if_possible)