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.
88 lines
3.2 KiB
88 lines
3.2 KiB
from random import randint
|
|
|
|
class Personnage:
|
|
def __init__(self,nom : str,cat : str) -> None:
|
|
self.nom = nom
|
|
self.pdv = 20
|
|
self.exp = 1
|
|
|
|
if cat.lower() == "guerrier":
|
|
self.cat = 0
|
|
self.inventaire = ["épée","potion"]
|
|
elif cat.lower() == "magicien":
|
|
self.cat = 1
|
|
self.inventaire = ["bâton","potion"]
|
|
elif cat.lower() == "voleur":
|
|
self.cat = 2
|
|
self.inventaire = ["dague","potion"]
|
|
elif cat.lower() == "elfe":
|
|
self.cat = 3
|
|
self.inventaire = ["arc","potion"]
|
|
|
|
def jet_attaque(self) -> int:
|
|
degatsAttaque = [10,10,3,8] #guerrier,magicien,voleur,elfe
|
|
return randint(1,20) + self.exp*degatsAttaque[self.cat]
|
|
|
|
def jet_defense(self) -> int:
|
|
degatsDefense = [8,7,9,10] #pareil
|
|
return randint(1,20) + self.exp*degatsDefense[self.cat]
|
|
|
|
def change_pdv(self,nb_pdv : int) -> None:
|
|
self.pdv += nb_pdv
|
|
if self.pdv < 0:
|
|
self.pdv = 0
|
|
def change_exp(self,nb_exp : int) -> None:
|
|
self.exp += nb_exp
|
|
|
|
def affiche_caracteristiques(self) -> None:
|
|
print(f"""Le personnage {self.nom} de catégorie {["guerrier",
|
|
"magicien","voleur","elfe"][self.cat]} a {self.pdv} points de vie et
|
|
{self.exp} point(s) d'experience """)
|
|
|
|
def affiche_inventaire(self) -> None:
|
|
print(f"Le joueur {self.nom} possède", *((item + ",")for item in self.inventaire),
|
|
"dans son inventaire")
|
|
|
|
def combat(perso1,perso2):
|
|
"Simule un combat entre deux objets créés avec Personnage"
|
|
jetAttaque1 = perso1.jet_attaque()
|
|
jetDefense1 = perso2.jet_defense()
|
|
if jetAttaque1 > jetDefense1:
|
|
pertePdv = -randint(1,8)
|
|
perso2.change_pdv(pertePdv)
|
|
print(f"""Le joueur {perso2.nom} n'arrive pas à se defendre contre l'attaque de
|
|
{perso1.nom} et perds {-pertePdv} points de vie.
|
|
""")
|
|
elif jetAttaque1 < jetDefense1:
|
|
pertePdv = -randint(1,4)
|
|
perso1.change_pdv(pertePdv)
|
|
print(f"""Le joueur {perso1.nom} essaye d'attaquer {perso2.nom} mais la
|
|
defense de {perso2.nom} est trop forte et {perso1.nom} perds {-pertePdv} points de vie.
|
|
""")
|
|
else:
|
|
print("Les deux joueurs sont de la meme force et rien ne se passe")
|
|
|
|
def main() -> None:
|
|
print("Bienvenue sur le jeu du millénaire !!! \n")
|
|
perso1 = Personnage(input("Comment s'appelle le personnage 1 ? "),
|
|
input("Dans quelle categorie est ce personnage ? (guerrier,magicien,voleur,elfe) "))
|
|
perso2 = Personnage(input("Comment s'appelle le personnage 2 ? "),
|
|
input("Dans quelle categorie est ce personnage ? (guerrier,magicien,voleur,elfe) "))
|
|
print()
|
|
while perso1.pdv > 0 and perso2.pdv > 0:
|
|
combat(perso1,perso2)
|
|
combat(perso2,perso1)
|
|
perso1.affiche_caracteristiques()
|
|
perso2.affiche_caracteristiques()
|
|
if perso1.pdv == 0:
|
|
print(f"""
|
|
{perso1.nom} a été battu par {perso2.nom}""")
|
|
elif perso2.pdv == 0:
|
|
print(f"""
|
|
{perso2.nom} a été battu par {perso1.nom}""")
|
|
else:
|
|
input("""
|
|
Appuyez sur entrée pour passer au round suivant
|
|
""")
|
|
|
|
main()
|