MEUNIER Marvyn
1 year ago
1 changed files with 74 additions and 0 deletions
@ -0,0 +1,74 @@ |
|||
|
|||
|
|||
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 == 'combattant': |
|||
self.inventaire = ['épée', 'potion'] |
|||
elif cat == 'sorcier': |
|||
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 ['combattant', 'sorcier'] 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 == 'combattant' else 7 if self.cat == 'sorcier' 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("Combattant1", "combattant") |
|||
personnage2 = Personnage("Sorcier1", "sorcier") |
|||
|
|||
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!") |
Loading…
Reference in new issue