from random import randint class Personnage : def __init__(self, nom, cat) : self.nom = nom self.pdv = 20 self.exp = 1 self.cat = cat if self.cat == "guerrier": self.inventaire = ["épée","potion"] if self.cat == "magicien": self.inventaire = ["bâton","potion"] if self.cat == "voleur": self.inventaire = ["dague","potion"] if self.cat == "elfe": self.inventaire = ["arc","potion"] def jet_attaque(self): """revoie le jet d'attaque""" lance = randint(1, 20) if self.cat == "guerrier": return lance + self.exp * 10 if self.cat == "magicien": return lance + self.exp * 10 if self.cat == "voleur": return lance + self.exp * 3 if self.cat == "elfe": return lance + self.exp * 8 def jet_defence(self): """revoie le jet de défence""" lance = randint(1, 20) if self.cat == "guerrier": return lance + self.exp * 8 if self.cat == "magicien": return lance + self.exp * 7 if self.cat == "voleur": return lance + self.exp * 9 if self.cat == "elfe": return lance + self.exp * 10 def change_pdv(self, nb_pdv): """on ajoute un entier positif ou négatif aux points de vie du perso""" self.pdv = self.pdv + nb_pdv def change_exp(self, nb_exp): """on ajoute un entier positif à l'experience du perso""" self.exp = self.exp + nb_exp def affiche_carracteristiques(self): print("nom perso , catégorie perso, points de vie perso, expérience perso") def affiche_inventaire(self): if self.cat == "guerrier": print("le personnage a : épée, potion ") if self.cat == "magicien": print("le personnage a : bâton, potion ") if self.cat == "voleur": print("le personnage a : dague, potion ") if self.cat == "elfe": print("le personnage a : arc, potion") perso1 = Personnage("toto", "guerrier") return affiche_inventaire perso2 = Personnage("bob", "elfe")