Fight other entities

This commit is contained in:
Yohann D'ANELLO 2020-11-11 00:50:47 +01:00
parent 5addd42535
commit 9909b12501
3 changed files with 24 additions and 0 deletions

View File

@ -1,3 +1,5 @@
from random import randint
from ..interfaces import FightingEntity from ..interfaces import FightingEntity
@ -26,7 +28,22 @@ class Player(FightingEntity):
self.level += 1 self.level += 1
self.current_xp -= self.max_xp self.current_xp -= self.max_xp
self.max_xp = self.level * 10 self.max_xp = self.level * 10
self.health = self.maxhealth
def add_xp(self, xp: int) -> None: def add_xp(self, xp: int) -> None:
self.current_xp += xp self.current_xp += xp
self.level_up() 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

View File

@ -24,6 +24,7 @@ class KeyValues(Enum):
RIGHT = auto() RIGHT = auto()
ENTER = auto() ENTER = auto()
SPACE = auto() SPACE = auto()
FIGHT = auto()
class Game: class Game:
@ -88,6 +89,8 @@ class Game:
elif key in (self.settings.KEY_UP_PRIMARY, elif key in (self.settings.KEY_UP_PRIMARY,
self.settings.KEY_UP_SECONDARY): self.settings.KEY_UP_SECONDARY):
return KeyValues.UP return KeyValues.UP
elif key == self.settings.KEY_FIGHT:
return KeyValues.FIGHT
elif key == self.settings.KEY_ENTER: elif key == self.settings.KEY_ENTER:
return KeyValues.ENTER return KeyValues.ENTER
elif key == ' ': elif key == ' ':
@ -122,6 +125,9 @@ class Game:
elif key == KeyValues.RIGHT: elif key == KeyValues.RIGHT:
if self.player.move_right(): if self.player.move_right():
self.map.tick() self.map.tick()
elif key == KeyValues.FIGHT:
if self.player.fight():
self.map.tick()
elif key == KeyValues.SPACE: elif key == KeyValues.SPACE:
self.state = GameMode.MAINMENU self.state = GameMode.MAINMENU

View File

@ -27,6 +27,7 @@ class Settings:
['d', 'Touche principale pour aller vers la droite'] ['d', 'Touche principale pour aller vers la droite']
self.KEY_RIGHT_SECONDARY = \ self.KEY_RIGHT_SECONDARY = \
['KEY_RIGHT', 'Touche secondaire pour aller vers la droite'] ['KEY_RIGHT', 'Touche secondaire pour aller vers la droite']
self.KEY_FIGHT = ['f', 'Touche pour frapper un ennemi']
self.KEY_ENTER = \ self.KEY_ENTER = \
['\n', 'Touche pour valider un menu'] ['\n', 'Touche pour valider un menu']
self.TEXTURE_PACK = ['ascii', 'Pack de textures utilisé'] self.TEXTURE_PACK = ['ascii', 'Pack de textures utilisé']