nicolas
2 months ago
1 changed files with 84 additions and 0 deletions
@ -0,0 +1,84 @@ |
|||
### Classe qui répond au cahier des charges |
|||
### La partie jeux est un peu succinte, il faut appeler la fonction |
|||
### on ne peut pas choisir les personnages |
|||
### le joueur 1 gagne tout le temps ! On sort de la boucle forcement après le premier tour... |
|||
### attaquant et defenseur doivent tourner |
|||
### note : 13/20 (classe : 12/12 prog : 1/8) |
|||
|
|||
from random import randint |
|||
|
|||
class Personnage : |
|||
def __init__ (self, nom, cat): |
|||
self.nom = nom |
|||
self.pdv = 20 |
|||
self.exp = 1 |
|||
self.cat = cat |
|||
if cat == 'guerrier': |
|||
self.inv = ['epee', 'potion'] |
|||
elif cat == 'magicien': |
|||
self.inv = ['baton'] |
|||
elif cat == 'voleur': |
|||
self.inv = ['dague', 'potion'] |
|||
elif cat == 'elfe': |
|||
self.inv = ['arc''potion'] |
|||
|
|||
def jet_attaque(self): |
|||
if self.cat == 'guerrier' or self.cat == 'magicien': |
|||
coef = 10 |
|||
elif self.cat == 'voleur': |
|||
coef = 3 |
|||
elif self.cat == 'elfe': |
|||
coef = 8 |
|||
return randint(1,20) + (self.exp*coef) |
|||
|
|||
def jet_defense(self): |
|||
if self.cat == 'guerrier': |
|||
coef = 8 |
|||
elif self.cat == 'magicien': |
|||
coef = 7 |
|||
elif self.cat == 'voleur': |
|||
coef = 9 |
|||
elif self.cat == 'elfe': |
|||
coef = 10 |
|||
return randint(1,20) + (self.exp*coef) |
|||
|
|||
|
|||
|
|||
def change_pdv(self , nb_pdv): |
|||
self.pdv = nb_pdv + self.pdv |
|||
|
|||
|
|||
def change_exp(self , nb_exp): |
|||
self.exp = nb_exp + self.exp |
|||
|
|||
def affiche_caracteristiques(self): |
|||
print(f"votre nom est ", {self.nom}) |
|||
print(f"votre categorie est", {self.cat}) |
|||
print(f"vos points de vie sont", {self.pdv}) |
|||
print(f"votre exp est de", {self.exp}) |
|||
|
|||
def affiche_inventaire(self): |
|||
print(self.inv) |
|||
|
|||
def combat(j1,j2): |
|||
while j1.pdv > 0 and j2.pdv > 0: |
|||
att = j1.jet_attaque() |
|||
defence = j2.jet_defense() |
|||
if att > defence : |
|||
degat = randint(1, 8) |
|||
j2.change_pdv(-degat) |
|||
else: |
|||
degat = randint(1, 4) |
|||
j2.change_pdv(-degat) |
|||
if j1.pdv > 0 : |
|||
j1.change_exp(1) |
|||
return "j1 bravo tu as gagné +1xp" |
|||
else: |
|||
j2.change_exp(1) |
|||
return "j2 bravo tu a gagné +1xp" |
|||
|
|||
|
|||
|
|||
|
|||
j1 = Personnage('ayoub','guerrier') |
|||
j2 = Personnage('wilfried','magicien') |
Loading…
Reference in new issue