From f45887644572a3357b0a754c06ce7166c1ffedcf Mon Sep 17 00:00:00 2001 From: Kalyax Date: Sun, 18 Sep 2022 18:58:59 +0200 Subject: [PATCH] fini? --- game/core.py | 28 ++++++++++++++++++++++++++-- game/personnage.py | 20 +++++++++++++++----- graphics/layers.py | 29 +++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/game/core.py b/game/core.py index 57fe7ea..042e81d 100644 --- a/game/core.py +++ b/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 @@ -36,4 +36,28 @@ class Game: PopUp(1, "Vous avez perdu! Relancez le jeu pour continuer...", True) if self.ennemy.get_hp() == 0: self.ennemy = self.rand_ennemy() - PopUp(1, "Ennemi vaincu!") \ No newline at end of file + + 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}") \ No newline at end of file diff --git a/game/personnage.py b/game/personnage.py index c44a464..1883097 100644 --- a/game/personnage.py +++ b/game/personnage.py @@ -16,8 +16,8 @@ class StatsSet: class ClassType(Enum): GUERRIER = StatsSet(20, 10, 15, 5, 8) MAGICIEN = StatsSet(15, 15, 6, 5, 7) - VOLEUR = StatsSet(17, 22, 9, 7, 9) - ELFE = StatsSet(12, 30, 1, 5, 10) + VOLEUR = StatsSet(9, 30, 9, 7, 9) + ELFE = StatsSet(13, 22, 1, 5, 10) class Personnage: def __init__(self, nom, class_type, place): @@ -25,11 +25,12 @@ class Personnage: self.class_name = class_type.name self.class_type = class_type.value - self.__hp = self.class_type.hp self.__xp = 1 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) @@ -48,6 +49,8 @@ class Personnage: def change_hp(self, nb_hp): if self.__hp - nb_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: self.__hp -= nb_hp @@ -75,7 +78,7 @@ class Personnage: def reduced_stats(self): return(f"Ennemi: {self.nom}", 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") DAGUE = ItemMeta("Dague", "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)) \ No newline at end of file diff --git a/graphics/layers.py b/graphics/layers.py index 287d9cb..5c17a9d 100644 --- a/graphics/layers.py +++ b/graphics/layers.py @@ -42,6 +42,24 @@ class GUI(Layer): color = (Colors.REDBG, Colors.BLACK) if self.__buttons[self.__current] == button else (Colors.WHITEBG, Colors.BLACK) self.put_string(button, x, self.y-10, color) 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 @@ -58,12 +76,15 @@ class GUI(Layer): Screen.instance.game.attack(attacker, victim) elif self.__current == 1: self.__inventaire = True - self.__current = 0 - self.__buttons = ["Retour", "Potion", Screen.instance.game.personnage.arme.meta.name] + self.__buttons = ["Retour", "Potion", "Arme"] else: if self.__current == 0: self.__inventaire = False 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 y = 0 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]) x += 1 if x == length: