from random import randint from ..interfaces import FightingEntity class Player(FightingEntity): name = "player" maxhealth: int = 20 strength: int = 5 intelligence: int = 1 charisma: int = 1 dexterity: int = 1 constitution: int = 1 level: int = 1 current_xp: int = 0 max_xp: int = 10 def move(self, y: int, x: int) -> None: """ When the player moves, move the camera of the map. """ super().move(y, x) self.map.currenty = y self.map.currentx = x def level_up(self) -> None: while self.current_xp > self.max_xp: self.level += 1 self.current_xp -= self.max_xp self.max_xp = self.level * 10 self.health = self.maxhealth def add_xp(self, xp: int) -> None: self.current_xp += xp self.level_up() def fight(self) -> bool: """ Fight all f """ one_fight = False for entity in self.map.entities: if entity != self and isinstance(entity, FightingEntity) and\ self.distance_squared(entity) <= 1: self.hit(entity) one_fight = True if entity.dead: self.add_xp(randint(3, 7)) return one_fight