from random import randint from graphics.layers import Sprite class Category: def __init__(self, nom, __expcoef, inventaire): self.nom = nom self.pdv = __expcoef self.inventaire = inventaire class Material: POTION = "POTION" EPEE = "EPEE" BATON = "BATON" DAGUE = "DAGUE" ARC = "ARC" class Personnage: def __init__(self, nom, cat, personnage_type): self.nom = nom self.__pdv = 20 self.__exp = 1 self.cat = cat if cat == "Guerrier": self.inventaire = [Material.EPEE, Material.POTION] self.__expcoef = 10 elif cat == "Magicien": self.inventaire = [Material.BATON, Material.POTION] self.__expcoef = 10 elif cat == "Voleur": self.inventaire = [Material.DAGUE, Material.POTION] self.__expcoef = 3 elif cat == "Elfe": self.inventaire = [Material.ARC, Material.POTION] self.__expcoef = 8 Sprite(3, cat, personnage_type) def jet_attaque(self): damage = randint(1, 20) self.change_exp(self.__expcoef * self.__exp) return damage def jet_defense(self): damage = randint(1, 20) self.change_exp(self.__expcoef * self.__exp) return damage def get_pdv(self): return self.__pdv def change_pdv(self, nb_pdv): if self.__pdv - nb_pdv < 0: self.__pdv = 0 else: self.__pdv -= nb_pdv def get_xp(self): return self.__exp def change_exp(self, nb_exp): if nb_exp > 0: self.__exp += nb_exp else: raise ValueError("nb_exp attends un nombre positif") def affiche_caracteristiques(self): return (f"Nom: {self.nom}", f"Type de classe: {self.cat}", f"Vie: {self.__pdv}", f"Expérience: {self.__exp}", f"XPCOEF: {self.__expcoef}" ) def affiche_inventaire(self): return ["- "+item for item in self.inventaire]