You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.7 KiB

from random import randint
class Personnage :
def __init__(self, nom, cat) :
self.nom = nom
self.cat = cat.lower()
self.pv = 20
self.exp = 1
if self.cat == "guerrier" :
self.inv = ["épée", "potion"]
elif self.cat == "magicien" :
self.inv = ["bâton", "potion"]
elif self.cat == "voleur" :
self.inv = ["dague","potion"]
elif self.cat == "elfe" :
self.inv = ["arc","potion"]
def jet_attaque(self) :
resultat_de = randint(1, 20)
if self.cat == "guerrier" or self.cat == "magicien" :
return resultat_de+self.exp*10
elif self.cat == "voleur" :
return resultat_de+self.exp*3
elif self.cat == "elfe" :
return resultat_de+self.exp*8
def jet_defense(self) :
resultat_de = randint(1,20)
if self.cat == "guerrier" :
return resultat_de+self.exp*8
elif self.cat == "magicien" :
return resultat_de+self.exp*7
elif self.cat == "voleur" :
return resultat_de+self.exp*9
elif self.cat == "elfe" :
return resultat_de+self.exp*10
def change_pv(self, nb_pv) :
self.pv += nb_pv
def change_exp(self, nb_exp) :
self.exp += nb_exp
def affiche_caracteristiques(self) :
print(f"Bonjour {self.nom} le {self.cat}, voici tes caractéristiques actuelle :\n- {self.pv} PV \n- {self.exp} EXP")
def affiche_inventaire(self) :
print(f"Bonjour {self.nom}, voici ton inventaire :")
for i in range(len(self.inv)) :
print(f"- {self.inv[i]}")
def combat() :
perso1 = Personnage(input("Comment s'appelle le premier joueur ? "), input("Quelle est sa catégorie ? (guerrier, magicien, voleur, elfe) "))
perso2 = Personnage(input("Comment s'appelle le second joueur ? "), input("Quelle est sa catégorie ? (guerrier, magicien, voleur, elfe) "))
print()
degats = perso1.jet_attaque()
defense = perso2.jet_defense()
if degats == defense :
print("il y a égalité sur les lancés, personne ne prend de dégâts")
elif degats > defense :
perte_pv = randint(-8,-1)
perso2.change_pv(perte_pv)
print(f"{perso1.nom} inflige {perte_pv} dégâts à {perso2.nom}")
perso2.affiche_caracteristiques()
elif degats < defense :
perte_pv = randint(-4,-1)
perso1.change_pv(perte_pv)
print(f"{perso2.nom} se défend parfaitement et inflige même {perte_pv} dégâts de contre à {perso1.nom}")
perso1.affiche_caracteristiques()
combat()
corentin = Personnage("Corentin", "guerrier")
xuan = Personnage("Xuan", "Elfe")