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.

109 lines
3.6 KiB

from random import randint
class Personnage :
def __init__(self,nom,cat):
self.nom = nom
self.pdv = 20
self.exp = 1
self.cat = cat
if self.cat == "guerrier":
self.inventaire = ["épée","potion"]
if self.cat == "magicien":
self.inventaire = ["bâton","potion"]
if self.cat == "voleur":
self.inventaire = ["dague","potion"]
if self.cat == "elfe":
self.inventaire = ["arc","potion"]
def jet_attaque (self):
if self.cat == "guerrier":
jet = randint(1,20) + self.exp * 10
if self.cat == "magicien":
jet = randint(1,20) + self.exp * 10
if self.cat == "voleur":
jet = randint(1,20) + self.exp * 3
if self.cat == "elfe":
jet = randint(1,20) + self.exp * 8
#print(self.cat)
return jet
def jet_defense (self):
if self.cat == "guerrier":
jet = randint(1,20) + self.exp * 8
if self.cat == "magicien":
jet = randint(1,20) + self.exp * 7
if self.cat == "voleur":
jet = randint(1,20) + self.exp * 9
if self.cat == "elfe":
jet = randint(1,20) + self.exp * 10
#print(self.cat)
return jet
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 ("mon nom est",self.nom,"je suis un" ,self.cat, "j'ai",self.pdv ,
"point de vie", "et",self.exp ,"d'experience")
def affiche_inventaire (self):
print (self.inventaire)
def jeu ():
joueur_1_nom = input("quel est votre nom joueur 1 ? :")
joueur_1_cat = input ("quel catégorie voulez vous etre ?: 1= guerrier 2= magicien 3= voleur 4= elfe")
if joueur_1_cat == "1":
joueur_1_cat = "guerrier"
if joueur_1_cat == "2":
joueur_1_cat = "magicien"
if joueur_1_cat == "3":
joueur_1_cat = "voleur"
if joueur_1_cat == "4":
joueur_1_cat = "elfe"
joueur_2_nom = input("quel est votre nom joueur 2 ? :")
joueur_2_cat = input ("quel catégorie voulez vous etre ?: 1= guerrier 2= magicien 3= voleur 4= elfe")
if joueur_2_cat == "1":
joueur_2_cat = "guerrier"
if joueur_2_cat == "2":
joueur_2_cat = "magicien"
if joueur_2_cat == "3":
joueur_2_cat = "voleur"
if joueur_2_cat == "4":
joueur_2_cat = "elfe"
joueur_1 = Personnage (joueur_1_nom,joueur_1_cat)
joueur_2 = Personnage (joueur_2_nom,joueur_2_cat)
while joueur_1.pdv > 0 and joueur_2.pdv > 0 :
j1A = joueur_1.jet_attaque()
j2D = joueur_2.jet_defense()
if j1A > j2D:
joueur_1.change_pdv(-randint(1,8))
print(joueur_1_nom,"a attaqué",joueur_2_nom)
elif j1A< j2D:
joueur_1.change_pdv (-randint (1,4))
print(joueur_2_nom,"se defend contre",joueur_1_nom)
joueur_1.affiche_caracteristiques()
j2A = joueur_2.jet_attaque()
j1D = joueur_1.jet_defense()
if j2A > j1D:
joueur_1.change_pdv (- randint(1,8))
print(joueur_2_nom,"a attaqué",joueur_1_nom)
elif j2A < j1D :
joueur_2.change_pdv (- randint(1,4))
print(joueur_1_nom," se defend contre",joueur_2_nom)
joueur_2.affiche_caracteristiques()
if joueur_1.pdv > 0:
joueur_1.exp += 1
if joueur_2.pdv > 0:
joueur_2.exp += 1
jeu()