from random import randint class StatsSet(): #HP, ATK%, DEF%, CRIT, CRITRATE%, XPCOEF def __init__(self, hp, atkP, defP, crit, critrateP, xpcoef): self.hp = hp self.atkP = atkP self.defP = defP self.crit = crit self.critrateP = critrateP self.xpcoef = xpcoef class ClassType: GUERRIER = StatsSet(20, 10, 12, 5, 10, 8) MAGICIEN = StatsSet(16, 12, 6, 8, 15, 7) #VOLEUR = #ELF = @staticmethod def class_name(class_set): if class_set == ClassType.GUERRIER: return "GUERRIER" elif class_set == ClassType.MAGICIEN: return "MAGICIEN" class Personnage: def __init__(self, nom, class_type): self.nom = nom self.class_type = class_type self.__hp = self.class_type.hp self.stats = StatsSet(0, 0, 0, 0, 0, 0) self.__xp = 1 #self.inventaire = #self.element = def jet_attaque(self): damage = randint(1, 20) self.change_exp(self.class_type.xpcoef * self.__xp) return damage + damage * (self.class_type.atkP + self.stats.atkP) def jet_defense(self): damage = randint(1, 20) self.change_exp(self.class_type.xpcoef * self.__xp) return damage + damage * (self.class_type.defP + self.stats.defP) def get_hp(self): return self.__hp def change_hp(self, nb_hp): if self.__hp - nb_hp < 0: self.__hp = 0 else: self.__hp -= nb_hp def get_xp(self): return self.__xp def change_exp(self, nb_exp): if nb_exp > 0: self.__xp += nb_exp else: raise ValueError("nb_exp attends un nombre positif") def affiche_caracteristiques(self): return (f"Nom: {self.nom}", f"Type de classe: {ClassType.class_name(self.class_type)}", f"Vie: {self.__hp}", f"Expérience: {self.__xp}", "Stats (classe + personnage):", 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"- CRIT: {self.class_type.crit} + {self.stats.crit}", f"- CRITRATE%: {self.class_type.critrateP} + {self.stats.critrateP}", f"- XPCOEF: {self.class_type.xpcoef} + {self.stats.xpcoef}" )