From 574bede774e55e4e04bb2a33f44dbdb56a701456 Mon Sep 17 00:00:00 2001 From: Kalyax Date: Sun, 18 Sep 2022 18:12:03 +0200 Subject: [PATCH] CA MARCHE PRESQUE --- game/core.py | 4 +-- game/inventaire.py | 29 ------------------ game/personnage.py | 42 ++++++++++++++++++-------- graphics/layers.py | 73 +++++++++++++++++++++++++++++----------------- main.py | 2 +- 5 files changed, 80 insertions(+), 70 deletions(-) delete mode 100644 game/inventaire.py diff --git a/game/core.py b/game/core.py index 1745fbc..57fe7ea 100644 --- a/game/core.py +++ b/game/core.py @@ -26,10 +26,10 @@ class Game: def_jet = victim.jet_defense() if (atk_jet >= def_jet): rand = randint(1, 8) - victim.change_hp(rand + rand * ((attacker.class_type.atkP + attacker.stats.atkP)//100)) + victim.change_hp(rand + rand * ((attacker.class_type.atkP + attacker.arme.stats.atkP)//100)) else: rand = randint(1, 4) - attacker.change_hp(rand + rand * ((victim.class_type.defP + victim.stats.defP)//100)) + attacker.change_hp(rand + rand * ((victim.class_type.defP + victim.arme.stats.defP)//100)) if self.personnage.get_hp() == 0: for i in range(50): diff --git a/game/inventaire.py b/game/inventaire.py deleted file mode 100644 index 66d4857..0000000 --- a/game/inventaire.py +++ /dev/null @@ -1,29 +0,0 @@ -class Item: - def __init__(self, name): - self.name = name -class Arme(Item): - def __init__(self, name, stats_set): - super().__init__(name) - self.stats_set = stats_set - - def equip(): - pass - - -class Inventaire: - def __init__(self): - self.__content = [] - - def get_content(self): - return self.__content - - def add_item(self, item): - if isinstance(Item, item): - self.__content.append(item) - return self - else: - raise ValueError("item attends un objet Item") - - def remove_item(self, index): - self.__content.pop(index) - return self \ No newline at end of file diff --git a/game/personnage.py b/game/personnage.py index c54e32a..c44a464 100644 --- a/game/personnage.py +++ b/game/personnage.py @@ -13,14 +13,12 @@ class StatsSet: self.initiative = initiative self.xpcoef = xpcoef - 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) - class Personnage: def __init__(self, nom, class_type, place): self.nom = nom @@ -28,21 +26,22 @@ class Personnage: self.class_type = class_type.value self.__hp = self.class_type.hp - self.stats = StatsSet(0, 0, 0, 0, 0) self.__xp = 1 + self.potions = [Item(Material.POTION, 10)] + self.arme = Item(Material.EPEE, StatsSet(5, 5, 5, 5, 0)) + Sprite(3, self.class_name, place) - #self.inventaire = def jet_attaque(self): damage = randint(1, 20) self.change_exp(self.class_type.xpcoef * self.__xp) - return damage + self.class_type.initiative + self.stats.initiative + return damage + self.class_type.initiative + self.arme.stats.initiative def jet_defense(self): damage = randint(1, 20) self.change_exp(self.class_type.xpcoef * self.__xp) - return damage + self.class_type.initiative + self.stats.initiative + return damage + self.class_type.initiative + self.arme.stats.initiative def get_hp(self): return self.__hp @@ -66,15 +65,34 @@ class Personnage: f"Vie: {self.__hp}", f"Expérience: {self.__xp}", "Stats (classe + inventaire):", - f"- HP: {self.class_type.hp} + {self.stats.hp}", - f"- ATK%: {self.class_type.atkP} + {self.stats.atkP}", - f"- DEF%: {self.class_type.defP} + {self.stats.defP}", - f"- INITIATIVE: {self.class_type.initiative} + {self.stats.initiative}", - f"- XPCOEF: {self.class_type.xpcoef} + {self.stats.xpcoef}" + f"- HP: {self.class_type.hp} + {self.arme.stats.hp}", + f"- ATK%: {self.class_type.atkP} + {self.arme.stats.atkP}", + f"- DEF%: {self.class_type.defP} + {self.arme.stats.defP}", + f"- INITIATIVE: {self.class_type.initiative} + {self.arme.stats.initiative}", + f"- XPCOEF: {self.class_type.xpcoef} + {self.arme.stats.xpcoef}" ) def reduced_stats(self): return(f"Ennemi: {self.nom}", f"Type: {self.class_name}", f"Vie: {self.__hp}", - ) \ No newline at end of file + ) + + +class Item(): + def __init__(self, material, stats: int | StatsSet, meta=None): + self.material = material + self.meta = material.value if meta == None else meta + self.stats = stats + +class ItemMeta: + def __init__(self, name, description): + self.name = name + self.description = description + +class Material(Enum): + POTION = ItemMeta("Potion", "TODO") + EPEE = ItemMeta("Épée", "TODO") + BATON = ItemMeta("Bâton", "TODO") + DAGUE = ItemMeta("Dague", "TODO") + ARC = ItemMeta("Arc", "TODO") diff --git a/graphics/layers.py b/graphics/layers.py index 5d851f6..287d9cb 100644 --- a/graphics/layers.py +++ b/graphics/layers.py @@ -8,42 +8,63 @@ from re import match class GUI(Layer): """Calque du menu principal""" - def __init__(self, z_index, buttons): + def __init__(self, z_index): super().__init__(z_index, "gui") - self.buttons = buttons - self.current = 0 - + self.__current = 0 + self.__buttons = ["Attaquer", "Inventaire"] + self.__inventaire = False self.handle_keys = False + self.__page = 1 + def draw(self): super().draw() - x = 1 - for button in self.buttons: - 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.__inventaire == False: + x = 1 + for button in self.__buttons: + 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 + + stats = Screen.instance.game.personnage.affiche_caracteristiques() + for i in range(4): + self.put_string(stats[i], 1, self.y-8+i, [Colors.RED2]) + for i in range(6): + self.put_string(stats[i+4], (self.x-2)//3, self.y-8+i, [Colors.RED2]) + + ennemy_stats = Screen.instance.game.ennemy.reduced_stats() + for i in range(3): + self.put_string(ennemy_stats[i], self.x-(self.x-2)//3, self.y-8+i, [Colors.BLUE2]) - stats = Screen.instance.game.personnage.affiche_caracteristiques() - for i in range(4): - self.put_string(stats[i], 1, self.y-8+i, [Colors.RED2]) - for i in range(6): - self.put_string(stats[i+4], (self.x-2)//3, self.y-8+i, [Colors.RED2]) - - ennemy_stats = Screen.instance.game.ennemy.reduced_stats() - for i in range(3): - self.put_string(ennemy_stats[i], self.x-(self.x-2)//3, self.y-8+i, [Colors.BLUE2]) + else: + x = 1 + for button in self.__buttons: + 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 return self def key_handler(self, key): - if key == keys.RIGHT and self.current < len(self.buttons)-1: - self.current += 1 - elif key == keys.LEFT and self.current > 0: - self.current -= 1 - elif key == keys.ENTER and self.current == 0: - attacker = Screen.instance.game.personnage - victim = Screen.instance.game.ennemy - Screen.instance.game.attack(attacker, victim) + if key == keys.RIGHT and self.__current < len(self.__buttons)-1: + self.__current += 1 + elif key == keys.LEFT and self.__current > 0: + self.__current -= 1 + elif key == keys.ENTER: + if self.__inventaire == False: + if self.__current == 0: + attacker = Screen.instance.game.personnage + victim = Screen.instance.game.ennemy + 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] + else: + if self.__current == 0: + self.__inventaire = False + self.__buttons = ["Attaquer", "Inventaire"] + class StartPopUp(Layer): diff --git a/main.py b/main.py index f422061..a0cab77 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ if __name__ == "__main__": game = Game() screen = Screen(game) layers.StartPopUp(1) - layers.GUI(2, ["Attaquer", "Inventaire"]) + layers.GUI(2) listener.build_thread(screen).start()