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.
73 lines
2.4 KiB
73 lines
2.4 KiB
1 year ago
|
import random
|
||
|
|
||
|
class Personnage:
|
||
|
def __init__(self, nom, cat):
|
||
|
self.nom = nom
|
||
|
self.pdv = 20
|
||
|
self.exp = 1
|
||
|
self.cat = cat
|
||
|
self.inventaire = []
|
||
|
|
||
|
if cat == 'guerrier':
|
||
|
self.inventaire = ['épée', 'potion']
|
||
|
elif cat == 'magicien':
|
||
|
self.inventaire = ['bâton', 'potion']
|
||
|
elif cat == 'voleur':
|
||
|
self.inventaire = ['dague', 'potion']
|
||
|
elif cat == 'elfe':
|
||
|
self.inventaire = ['arc', 'potion']
|
||
|
|
||
|
def jet_attaque(self):
|
||
|
de_a_20_faces = random.randint(1, 20)
|
||
|
coefficient_classe = 10 if self.cat in ['guerrier', 'magicien'] else 3 if self.cat == 'voleur' else 8
|
||
|
return de_a_20_faces + self.exp * coefficient_classe
|
||
|
|
||
|
def jet_defense(self):
|
||
|
de_a_20_faces = random.randint(1, 20)
|
||
|
coefficient_classe = 8 if self.cat == 'guerrier' else 7 if self.cat == 'magicien' else 9 if self.cat == 'voleur' else 10
|
||
|
return de_a_20_faces + self.exp * coefficient_classe
|
||
|
|
||
|
def change_pdv(self, nb_pdv):
|
||
|
self.pdv += nb_pdv
|
||
|
|
||
|
def change_exp(self, nb_exp):
|
||
|
if nb_exp > 0:
|
||
|
self.exp += nb_exp
|
||
|
|
||
|
def affiche_caracteristiques(self):
|
||
|
print(f"Nom: {self.nom}")
|
||
|
print(f"Catégorie: {self.cat}")
|
||
|
print(f"Points de vie: {self.pdv}")
|
||
|
print(f"Expérience: {self.exp}")
|
||
|
|
||
|
def affiche_inventaire(self):
|
||
|
print(f"Inventaire de {self.nom}: {', '.join(self.inventaire)}")
|
||
|
|
||
|
personnage1 = Personnage("Guerrier1", "guerrier")
|
||
|
personnage2 = Personnage("Magicien1", "magicien")
|
||
|
|
||
|
while personnage1.pdv > 0 and personnage2.pdv > 0:
|
||
|
attaquant = personnage1 if random.random() < 0.5 else personnage2
|
||
|
defenseur = personnage2 if attaquant == personnage1 else personnage1
|
||
|
|
||
|
print(f"{attaquant.nom} attaque {defenseur.nom}!")
|
||
|
jet_attaque = attaquant.jet_attaque()
|
||
|
jet_defense = defenseur.jet_defense()
|
||
|
|
||
|
if jet_attaque > jet_defense:
|
||
|
degats = random.randint(1, 8)
|
||
|
defenseur.change_pdv(-degats)
|
||
|
print(f"{defenseur.nom} perd {degats} points de vie.")
|
||
|
else:
|
||
|
degats = random.randint(1, 4)
|
||
|
attaquant.change_pdv(-degats)
|
||
|
print(f"{attaquant.nom} perd {degats} points de vie.")
|
||
|
|
||
|
personnage1.affiche_caracteristiques()
|
||
|
personnage2.affiche_caracteristiques()
|
||
|
print()
|
||
|
|
||
|
gagnant = personnage1 if personnage1.pdv > 0 else personnage2
|
||
|
gagnant.change_exp(1)
|
||
|
print(f"{gagnant.nom} a gagné le combat et reçoit 1 point d'expérience!")
|