Kalyax 2 years ago
parent
commit
f458876445
  1. 28
      game/core.py
  2. 20
      game/personnage.py
  3. 29
      graphics/layers.py

28
game/core.py

@ -1,4 +1,4 @@
from game.personnage import Personnage, ClassType from game.personnage import Personnage, ClassType, Item, Material
from graphics.layers import Sprite, PopUp from graphics.layers import Sprite, PopUp
@ -36,4 +36,28 @@ class Game:
PopUp(1, "Vous avez perdu! Relancez le jeu pour continuer...", True) PopUp(1, "Vous avez perdu! Relancez le jeu pour continuer...", True)
if self.ennemy.get_hp() == 0: if self.ennemy.get_hp() == 0:
self.ennemy = self.rand_ennemy() self.ennemy = self.rand_ennemy()
PopUp(1, "Ennemi vaincu!")
potions = ""
for i in range(randint(0, 3)):
random = randint(5, 25)
self.personnage.potions.append(Item(Material.POTION, random))
potions += f"- Potion de {random}HP\n"
random = randint(0, 4)
arme = ""
stat = randint(1, 4)
stats = self.personnage.arme.stats
if random == 0:
stats.hp += stat
arme = f"+ {stat} HP"
elif random == 1:
stats.atkP += stat
arme = f"+ {stat} ATK%"
elif random == 2:
stats.defP += stat
arme = f"+ {stat} DEF%"
elif random == 3:
stats.initiative += stat
arme = f"+ {stat} INITIATIVE"
PopUp(1, f"Ennemi vaincu!\n{potions}\n{arme}")

20
game/personnage.py

@ -16,8 +16,8 @@ class StatsSet:
class ClassType(Enum): class ClassType(Enum):
GUERRIER = StatsSet(20, 10, 15, 5, 8) GUERRIER = StatsSet(20, 10, 15, 5, 8)
MAGICIEN = StatsSet(15, 15, 6, 5, 7) MAGICIEN = StatsSet(15, 15, 6, 5, 7)
VOLEUR = StatsSet(17, 22, 9, 7, 9) VOLEUR = StatsSet(9, 30, 9, 7, 9)
ELFE = StatsSet(12, 30, 1, 5, 10) ELFE = StatsSet(13, 22, 1, 5, 10)
class Personnage: class Personnage:
def __init__(self, nom, class_type, place): def __init__(self, nom, class_type, place):
@ -25,11 +25,12 @@ class Personnage:
self.class_name = class_type.name self.class_name = class_type.name
self.class_type = class_type.value self.class_type = class_type.value
self.__hp = self.class_type.hp
self.__xp = 1 self.__xp = 1
self.potions = [Item(Material.POTION, 10)] self.potions = [Item(Material.POTION, 10)]
self.arme = Item(Material.EPEE, StatsSet(5, 5, 5, 5, 0)) self.arme = Item(*ClassItem[self.class_name].value)
self.__hp = self.class_type.hp + self.arme.stats.hp
Sprite(3, self.class_name, place) Sprite(3, self.class_name, place)
@ -48,6 +49,8 @@ class Personnage:
def change_hp(self, nb_hp): def change_hp(self, nb_hp):
if self.__hp - nb_hp < 0: if self.__hp - nb_hp < 0:
self.__hp = 0 self.__hp = 0
elif self.__hp - nb_hp > self.class_type.hp + self.arme.stats.hp:
self.__hp = self.class_type.hp + self.arme.stats.hp
else: else:
self.__hp -= nb_hp self.__hp -= nb_hp
@ -75,7 +78,7 @@ class Personnage:
def reduced_stats(self): def reduced_stats(self):
return(f"Ennemi: {self.nom}", return(f"Ennemi: {self.nom}",
f"Type: {self.class_name}", f"Type: {self.class_name}",
f"Vie: {self.__hp}", f"Vie: {self.__hp}"
) )
@ -96,3 +99,10 @@ class Material(Enum):
BATON = ItemMeta("Bâton", "TODO") BATON = ItemMeta("Bâton", "TODO")
DAGUE = ItemMeta("Dague", "TODO") DAGUE = ItemMeta("Dague", "TODO")
ARC = ItemMeta("Arc", "TODO") ARC = ItemMeta("Arc", "TODO")
class ClassItem(Enum):
#HP, ATK, DEF, INITIATIVE, XPCOEF
GUERRIER = (Material.EPEE, StatsSet(3, 5, 2, 6, 0))
MAGICIEN = (Material.BATON, StatsSet(8, 1, 2, 3, 0))
VOLEUR = (Material.DAGUE, StatsSet(1, 9, 1, 1, 0))
ELFE = (Material.ARC, StatsSet(4, 2, 5, 3, 0))

29
graphics/layers.py

@ -43,6 +43,24 @@ class GUI(Layer):
self.put_string(button, x, self.y-10, color) self.put_string(button, x, self.y-10, color)
x += len(button)+1 x += len(button)+1
if self.__current == 0:
self.put_string(f"ENTREE pour retourner en arrière", 1, self.y-8, [Colors.RED2])
elif self.__current == 1:
potions = Screen.instance.game.personnage.potions
self.put_string(f"Nombre total de potions: {len(potions)}", 1, self.y-8, [Colors.RED2])
if len(potions) > 0:
self.put_string(f"Rénération de la prochaine potion: {potions[0].stats}", 1, self.y-7, [Colors.RED2])
self.put_string(f"ENTEE pour utiliser", 1, self.y-5, [Colors.RED2])
elif self.__current == 2:
arme = Screen.instance.game.personnage.arme
self.put_string(f"Nom: {arme.meta.name}", 1, self.y-8, [Colors.RED2])
self.put_string(f"Stats:", 1, self.y-7, [Colors.RED2])
self.put_string(f"- HP: {arme.stats.hp}", 1, self.y-6, [Colors.RED2])
self.put_string(f"- ATK%: {arme.stats.atkP}", 1, self.y-5, [Colors.RED2])
self.put_string(f"- DEF%: {arme.stats.defP}", 1, self.y-4, [Colors.RED2])
self.put_string(f"- INITIATIVE: {arme.stats.initiative}", 1, self.y-3, [Colors.RED2])
self.put_string(f"- XPCOEF: {arme.stats.xpcoef}", 1, self.y-2, [Colors.RED2])
return self return self
def key_handler(self, key): def key_handler(self, key):
@ -58,12 +76,15 @@ class GUI(Layer):
Screen.instance.game.attack(attacker, victim) Screen.instance.game.attack(attacker, victim)
elif self.__current == 1: elif self.__current == 1:
self.__inventaire = True self.__inventaire = True
self.__current = 0 self.__buttons = ["Retour", "Potion", "Arme"]
self.__buttons = ["Retour", "Potion", Screen.instance.game.personnage.arme.meta.name]
else: else:
if self.__current == 0: if self.__current == 0:
self.__inventaire = False self.__inventaire = False
self.__buttons = ["Attaquer", "Inventaire"] self.__buttons = ["Attaquer", "Inventaire"]
elif self.__current == 1 and len(Screen.instance.game.personnage.potions) > 0:
personnage = Screen.instance.game.personnage
personnage.change_hp(-1*personnage.potions[0].stats)
del personnage.potions[0]
@ -128,6 +149,10 @@ class PopUp(Layer):
x = 0 x = 0
y = 0 y = 0
for char in self.message: for char in self.message:
if char == "\n":
x = 0
y += 1
continue
self.put_char(char, self.x//3 + 1 + x, self.y//6 + 1 + y, [Colors.WHITEBG, Colors.BLACK]) self.put_char(char, self.x//3 + 1 + x, self.y//6 + 1 + y, [Colors.WHITEBG, Colors.BLACK])
x += 1 x += 1
if x == length: if x == length:

Loading…
Cancel
Save