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.
136 lines
4.3 KiB
136 lines
4.3 KiB
import tkinter as tk
|
|
import time
|
|
from random import randint
|
|
class Personnage:
|
|
def __init__ (self, nom, cat):
|
|
self.nom = nom
|
|
self.pdv = 20
|
|
self.exp = 1
|
|
self.cat = cat
|
|
self.inventaire = []
|
|
|
|
if self.cat == "guerrier":
|
|
self.inventaire = ["épée", "potion"]
|
|
self.coefatk = 10
|
|
self.coefdef = 8
|
|
|
|
elif self.cat == "magicien":
|
|
self.inventaire = ["bâton", "potion"]
|
|
self.coefatk = 10
|
|
self.coefdef = 7
|
|
|
|
elif self.cat == "voleur":
|
|
self.inventaire = ["dague", "potion"]
|
|
self.coefatk = 3
|
|
self.coefdef = 9
|
|
|
|
elif self.cat == "elfe":
|
|
self.inventaire = ["arc", "potion"]
|
|
self.coefatk = 8
|
|
self.coefdef = 10
|
|
|
|
else:
|
|
raise ValueError ("La classe selectionné n'est pas disponible.")
|
|
|
|
def jet_attaque(self):
|
|
atkdé = randint(1, 20)
|
|
return self.exp * self.coefatk + atkdé
|
|
|
|
def jet_defense(self):
|
|
defdé = randint(1, 20)
|
|
return self.exp * self.coefdef + defdé
|
|
|
|
def change_pdv(self):
|
|
self.pdv += nb_pdv
|
|
return self.pdv
|
|
|
|
def change_exp(self):
|
|
nb_exp = 1
|
|
self.exp += nb_exp
|
|
return self.exp
|
|
|
|
def affiche_caracteristiques(self):
|
|
print(f"NOM: {self.nom} \n CATEGORIE : {self.cat} \n PV : {self.pdv} \n XP : {self.exp}")
|
|
|
|
def affiche_inventaire(self):
|
|
print(f"Dans votre sac vous avez : {self.inventaire}")
|
|
|
|
# Partie Jeu
|
|
|
|
def game():
|
|
#Joueur N°1 (l'attaquant)
|
|
Pl1_name = input("Comment vous nommez-vous cher aventurier ? ")
|
|
print("Bonjour cher", Pl1_name)
|
|
Pl1_cat = input("Quelle catégorie voulez-vous être ? \n1: Guerrier \n2: Magicien \n3: Voleur \n4: Elfe\n")
|
|
|
|
if Pl1_cat == "1":
|
|
Pl1_cat = "guerrier"
|
|
elif Pl1_cat == "2":
|
|
Pl1_cat = "magicien"
|
|
elif Pl1_cat == "3":
|
|
Pl1_cat = "voleur"
|
|
elif Pl1_cat == "4":
|
|
Pl1_cat = "elfe"
|
|
|
|
print("Vous etes désormais un(e)", Pl1_cat)
|
|
|
|
#Joueur N°2 (le défenseur)
|
|
Pl2_name = input("Et vous, aventurier N°2, comment vous nommez-vous ? ")
|
|
print("Bonjour cher", Pl1_name)
|
|
Pl2_cat = input("Quelle catégorie voulez-vous être ? \n1: Guerrier \n2: Magicien \n3: Voleur \n4: Elfe\n")
|
|
|
|
if Pl2_cat == "1":
|
|
Pl2_cat = "guerrier"
|
|
elif Pl2_cat == "2":
|
|
Pl2_cat = "magicien"
|
|
elif Pl2_cat == "3":
|
|
Pl2_cat = "voleur"
|
|
elif Pl2_cat == "4":
|
|
Pl2_cat = "elfe"
|
|
|
|
print("Vous etes maintenant un(e)", Pl2_cat)
|
|
|
|
Player_1 = Personnage(Pl1_name, Pl1_cat)
|
|
Player_2 = Personnage(Pl2_name, Pl2_cat)
|
|
|
|
print(Player_1.affiche_caracteristiques(), Player_1.affiche_inventaire())
|
|
|
|
time.sleep(1.5)
|
|
|
|
print(Player_2.affiche_caracteristiques(), Player_2.affiche_inventaire())
|
|
|
|
time.sleep(2.5)
|
|
|
|
|
|
#La suite du programme ne marche pas "TypeError: 'int' object is not callable", j'ai beau chercher comment règler l'érreur je n'y arrive pas."
|
|
#De plus, il a pas l'air d'être très bon
|
|
while Player_1.pdv() > 0 and Player_2.pdv() > 0:
|
|
Attaquant = Player_1.jet_attaque()
|
|
Defenseur = Player_2.jet_defense()
|
|
if Attaquant > Defenseur:
|
|
nb_pdv = -(randint(1, 8))
|
|
Player_2.change_pdv()
|
|
print(Player_2.nom(), "a été blessé lors de l'attaque, il a", Player_2.pdv(), "PV")
|
|
else:
|
|
nb_pdv = -(randint(1, 4))
|
|
Player_1.change_pdv()
|
|
print(Player_1.nom(), "a été blessé suite à la défense, il a", Player_1.pdv(), "PV")
|
|
time.sleep(3)
|
|
|
|
Attaquant = Player_1.jet_defense()
|
|
Defenseur = Player_2.jet_attaque()
|
|
|
|
if Defenseur > Attaquant:
|
|
nb_pdv = -(randint(1, 8))
|
|
Player_1.change_pdv()
|
|
print(Player_1.nom(), "a été blessé lors de l'attaque, il a", Player_1.pdv(), "PV")
|
|
else:
|
|
nb_pdv = -(randint(1, 4))
|
|
Player_2.change_pdv()
|
|
print(Player_2.nom(), "a été blessé suite à la défense, il a", Player_2.pdv(), "PV")
|
|
time.sleep(3)
|
|
break
|
|
if Player_1.pdv() >= 1:
|
|
print(Player_1.nom(), "a gagné.")
|
|
else :
|
|
print(Player_2.nom(), "a gagné.")
|