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.
123 lines
3.7 KiB
123 lines
3.7 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"]
|
|
elif self.cat == "magicien":
|
|
self.inventaire = ["bâton", "potion"]
|
|
elif self.cat == "voleur":
|
|
self.inventaire = ["dague", "potion"]
|
|
elif self.cat == "elfe":
|
|
self.inventaire = ["arc", "potion"]
|
|
|
|
def jet_attaque(self):
|
|
de = randint(0, 20)
|
|
if self.cat == "guerrier" or self.cat == "magicien":
|
|
return de + self.exp*10
|
|
elif self.cat == "voleur":
|
|
return de + self.exp*3
|
|
elif self.cat == "elfe":
|
|
return de + self.exp*8
|
|
|
|
def jet_defense(self):
|
|
de = randint(0, 20)
|
|
if self.cat == "guerrier":
|
|
return de + self.exp*8
|
|
elif self.cat == "magicien":
|
|
return de + self.exp*7
|
|
elif self.cat == "voleur":
|
|
return de + self.exp*9
|
|
elif self.cat == "elfe":
|
|
return de + self.exp*10
|
|
|
|
def change_pdv(self, nb_pdv):
|
|
self.pdv = self.pdv + nb_pdv
|
|
|
|
def change_exp(self, nb_exp):
|
|
self.exp = self.exp + nb_exp
|
|
|
|
def affiche_caracteristiques(self):
|
|
print("Nom :", self.nom, ", Catégorie :", self.cat, ", Points de vie :", self.pdv, ", Expérience :", self.exp)
|
|
|
|
def affiche_inventaire(self):
|
|
print( self.nom, "a dans son inventraire :", self.inventaire)
|
|
|
|
print("quel est le nom du joueur 1?")
|
|
joueur1 = input()
|
|
print("Est-il un guerrier(1), un magicien(2), un voleur(3) ou un elfe(4)?")
|
|
categorie_j1 = int(input())
|
|
if categorie_j1 == 1:
|
|
cat_j1 = "guerrier"
|
|
elif categorie_j1 == 2:
|
|
cat_j1 = "magicien"
|
|
elif categorie_j1 == 3:
|
|
cat_j1 = "voleur"
|
|
elif categorie_j1 == 4:
|
|
cat_j1 = "elfe"
|
|
|
|
print("quel est le nom du joueur 2?")
|
|
joueur2 = input()
|
|
print("Est-il un guerrier(1), un magicien(2), un voleur(3) ou un elfe(4)?")
|
|
categorie_j2 = int(input())
|
|
if categorie_j2 == 1:
|
|
cat_j2 = "guerrier"
|
|
elif categorie_j2 == 2:
|
|
cat_j2 = "magicien"
|
|
elif categorie_j2 == 3:
|
|
cat_j2 = "voleur"
|
|
elif categorie_j2 == 4:
|
|
cat_j2 = "elfe"
|
|
|
|
j1 = Personnage(joueur1, cat_j1)
|
|
j2 =Personnage(joueur2, cat_j2)
|
|
attaquant = j1
|
|
defenseur = j2
|
|
|
|
def combat(j1, j2):
|
|
attaque = attaquant.jet_attaque()
|
|
defense = defenseur.jet_defense()
|
|
if attaque > defense :
|
|
attaquant.change_pdv(-randint(1,8))
|
|
else :
|
|
defenseur.change_pdv(-randint(1,4))
|
|
j1.affiche_caracteristiques()
|
|
j2.affiche_caracteristiques()
|
|
|
|
if attaquant.pdv - defenseur.pdv > 10 and defenseur.inventaire != [] and defenseur.pdv > 0:
|
|
print("Veux-tu utiliser quelque chose de ton inventaire? oui (1) non(2)")
|
|
defenseur.affiche_inventaire()
|
|
bonus = int(input())
|
|
if bonus == 1:
|
|
print("Utiliser arme pour affaiblir l'adversaire(1) ou potion pour se régenerer(2)")
|
|
objet = int(input())
|
|
if objet == 1 :
|
|
attaquant.change_pdv(-17)
|
|
defenseur.inventaire.pop(0)
|
|
elif objet == 2:
|
|
defenseur.change_pdv(25)
|
|
defenseur.inventaire.pop()
|
|
|
|
|
|
x = 1
|
|
while x == 1:
|
|
while j1.pdv > 0 and j2.pdv > 0:
|
|
combat(j1, j2)
|
|
attaquant, defenseur = defenseur, attaquant
|
|
if attaquant.pdv > defenseur.pdv :
|
|
attaquant.change_exp(1)
|
|
print (attaquant.nom , "a gagné !")
|
|
else :
|
|
defenseur.change_exp(1)
|
|
print ( defenseur.nom , "a gagné !")
|
|
attaquant.pdv = 20
|
|
defenseur.pdv = 20
|
|
print("rejouer? oui(1)/ non(0)")
|
|
x = int(input())
|
|
|
|
j1.affiche_caracteristiques()
|
|
j2.affiche_caracteristiques()
|