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.
132 lines
4.7 KiB
132 lines
4.7 KiB
from random import randint
|
|
|
|
class Personnage:
|
|
|
|
def __init__(self, nom, cat):
|
|
"""methode qui initialise les attributs"""
|
|
self.nom = nom
|
|
self.cat = cat
|
|
self.pdv = 20
|
|
self.exp = 1
|
|
if self.cat == "guerrier":
|
|
self.inventaire = ["sword, potion"] #retirer les # qui sont temporaire car non defini
|
|
elif self.cat == "magicien":
|
|
self.inventaire = ["stick, potion"]
|
|
elif self.cat == "voleur":
|
|
self.inventaire = ["dagger, potion"]
|
|
elif self.cat == "elfe":
|
|
self.inventaire = ["bow, potion"]
|
|
|
|
|
|
def jet_attaque(self):
|
|
""" Renvoie un jet dattaque qui est la somme d'un nombre aléatoire entre 1 et 20 a experience du joueur multiplier par coef"""
|
|
de = randint(1,20)
|
|
if self.cat == "guerrier" or self.cat == "magicien":
|
|
coef = 10
|
|
elif self.cat == "voleur":
|
|
coef = 3
|
|
else:
|
|
coef = 8
|
|
return de+(self.exp*coef)
|
|
|
|
|
|
def jet_defense(self):
|
|
""" Renvoie un jet de defense qui est la somme d'un nombre aléatoire
|
|
entre 1 et 20 a experience du joueur multiplier par coef"""
|
|
de = randint(1,20)
|
|
if self.cat == "guerrier":
|
|
coef = 8
|
|
elif self.cat == "magicien":
|
|
coef = 7
|
|
elif self.cat == "voleur":
|
|
coef = 9
|
|
else:
|
|
coef = 10
|
|
return de+(self.exp*coef)
|
|
|
|
|
|
def change_pdv(self, nb_pdv):
|
|
""" Change les point de vie du joueur en ajoutant la valeur positive ou
|
|
negative au point de vie qu'il possede"""
|
|
self.pdv += nb_pdv
|
|
|
|
|
|
def change_exp(self, nb_exp):
|
|
""" Change l'experience du joueur en ajoutant a ceux qu'il possede deja"""
|
|
self.exp += nb_exp
|
|
|
|
|
|
def affiche_caracteristique(self):
|
|
"""affiche les caracteristique du perso nom, cat, pdv, exp"""
|
|
print(" -------------------------\n \n",
|
|
f" Nom : {self.nom}\n",
|
|
f" Catégorie : {self.cat}\n",
|
|
f" Point de vie : {self.pdv}\n",
|
|
f" Expérience : {self.exp}\n \n",
|
|
"-------------------------\n")
|
|
|
|
|
|
def affiche_inventaire(self):
|
|
"""affiche le contenue de l'inventaire"""
|
|
print(" ------------------------------------\n \n",
|
|
f" Inventaire : {self.inventaire}\n \n",
|
|
"-----------------------------------")
|
|
|
|
|
|
def start():
|
|
""" Lance le programme demandant le nom des perso puis leur categorie et lance le duel"""
|
|
|
|
print(" ==============================================================================\n",
|
|
" Bienvenue, pour jouer a ce jeu il vous suffit d'ecrire -> start() dans la \n",
|
|
" console et le jeu lancera l'affrontement entre vos deux perso le gagnant\n",
|
|
" remportera 1 point d'éxperience\n",
|
|
"==============================================================================")
|
|
|
|
classe_p1 = ""
|
|
classe_p2 = ""
|
|
|
|
nom_p1 = input("Choisi le nom de ton premier personnage : ")
|
|
|
|
|
|
while classe_p1 != "guerrier" and classe_p1 != "magicien" and classe_p1 != "voleur" and classe_p1 != "elfe":
|
|
classe_p1 = input("Choisi une classe pour ton premier personnage (guerrier, magicien, voleur, elfe) : ")
|
|
|
|
perso1 = Personnage(nom_p1,classe_p1)
|
|
|
|
nom_p2 = input("Choisi le nom de ton second personnage : ")
|
|
|
|
while classe_p2 != "guerrier" and classe_p2 != "magicien" and classe_p2 != "voleur" and classe_p2 != "elfe":
|
|
classe_p2 = input("Choisi une classe pour ton second personnage (guerrier, magicien, voleur, elfe) : ")
|
|
|
|
perso2 = Personnage(nom_p2,classe_p2)
|
|
|
|
while perso1.pdv > 0 and perso2.pdv > 0:
|
|
attaquant = perso1.jet_attaque()
|
|
defenseur = perso2.jet_defense()
|
|
|
|
print(" ", nom_p1, "fait un jet d'attaque de ", attaquant, " et ",nom_p2," un jet",
|
|
" de defense de ", defenseur, " alors : ")
|
|
if attaquant > defenseur:
|
|
r = randint(1,8)
|
|
perso2.change_pdv(-r)
|
|
print(nom_p2,"perd ", r , " point de vie !!")
|
|
|
|
else:
|
|
r = randint(1,4)
|
|
perso1.change_pdv(-r)
|
|
print(nom_p1,"perd ", r , " point de vie !!")
|
|
|
|
perso1.affiche_caracteristique()
|
|
perso2.affiche_caracteristique()
|
|
|
|
if perso2.pdv <= 0:
|
|
perso1.change_exp(1)
|
|
print(nom_p2, "as perdu ",nom_p1,f"gagne 1 d'experience, il en a maintenant {perso1.exp}")
|
|
|
|
else:
|
|
perso2.change_exp(1)
|
|
print(nom_p1, "as perdu ",nom_p2,f"gagne 1 d'experience, il en a maintenant {perso2.exp}")
|
|
|
|
|
|
start()
|
|
|