KC_ZAY
3 weeks ago
1 changed files with 128 additions and 0 deletions
@ -0,0 +1,128 @@ |
|||||||
|
import random as rd |
||||||
|
|
||||||
|
class Monstre: |
||||||
|
def __init__(self, nom, dsc, img=None, obj=None) -> None: |
||||||
|
self.nom = nom |
||||||
|
self.dsc = dsc |
||||||
|
self.img = img |
||||||
|
self.obj = obj |
||||||
|
self.habilite = rd.randint(1,10) |
||||||
|
self.endurance = rd.randint(1,10) |
||||||
|
self.force = 2 |
||||||
|
self.courage = rd.randint(1,10) |
||||||
|
if 'Squelette' in nom: |
||||||
|
self.habilite = 4 |
||||||
|
self.endurance = 4 |
||||||
|
self.courage = 4 |
||||||
|
|
||||||
|
def get_description(self:'Monstre') -> str: |
||||||
|
return self.dsc |
||||||
|
|
||||||
|
def get_carac(self:'Monstre') -> str: |
||||||
|
return f"{self.nom} H{self.habilite} E{self.endurance} F{self.force} C{self.courage}" |
||||||
|
|
||||||
|
def est_hs(self:'Monstre')->bool: |
||||||
|
return self.endurance <= 0 |
||||||
|
|
||||||
|
def subir_degats(self:'Monstre', degats:int) -> None: |
||||||
|
if degats > 0: |
||||||
|
self.endurance = self.endurance - degats |
||||||
|
|
||||||
|
class Personnage: |
||||||
|
def __init__(self, nom) -> None: |
||||||
|
self.nom=nom |
||||||
|
self.habilite = 5+rd.randint(1,4) |
||||||
|
self.endurance = 8+rd.randint(1,8) |
||||||
|
self.charisme = rd.randint(1,10) |
||||||
|
self.vigilance = rd.randint(1,10) |
||||||
|
self.force = 2 |
||||||
|
self.courage = rd.randint(1,10) |
||||||
|
# self.discretion = |
||||||
|
# self.lieu = None |
||||||
|
# self.lieux_precedents = |
||||||
|
self.objet = None |
||||||
|
|
||||||
|
def est_hs(self:'Personnage') -> bool: |
||||||
|
self.endurance <=0 |
||||||
|
|
||||||
|
def get_carac(self:'Personnage') -> str: |
||||||
|
return f"{self.nom} H{self.habilite} E{self.endurance} F{self.force} C{self.courage} V{self.vigilance} \n{self.objet}" |
||||||
|
|
||||||
|
def subir_degats(self:'Personnage', degats:int) -> None: |
||||||
|
if degats > 0: |
||||||
|
self.endurance = self.endurance - degats |
||||||
|
|
||||||
|
def soigner(self:'Personnage', soins:int) -> None: |
||||||
|
if soins > 0: |
||||||
|
self.endurance = self.endurance + soins |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def combattre(self:'Personnage', adversaire: 'Monstre') -> tuple: |
||||||
|
# Lancer les dés pour le personnage |
||||||
|
personnage_de1 = rd.randint(1, 6) |
||||||
|
personnage_de2 = rd.randint(1, 6) |
||||||
|
score_personnage = personnage_de1 + personnage_de2 + self.habilite |
||||||
|
print(f"{self.nom} lance {personnage_de1} et {personnage_de2}, score total = {score_personnage}") |
||||||
|
|
||||||
|
# Lancer les dés pour le monstre |
||||||
|
monstre_de1 = rd.randint(1, 6) |
||||||
|
monstre_de2 = rd.randint(1, 6) |
||||||
|
score_monstre = monstre_de1 + monstre_de2 + adversaire.habilite |
||||||
|
print(f"{adversaire.nom} lance {monstre_de1} et {monstre_de2}, score total = {score_monstre}") |
||||||
|
|
||||||
|
# Vérifier si l'un des deux a fait un double |
||||||
|
crit_personnage = (personnage_de1 == personnage_de2) |
||||||
|
crit_monstre = (monstre_de1 == monstre_de2) |
||||||
|
|
||||||
|
# Calculer les dégâts |
||||||
|
degats_personnage = self.force |
||||||
|
degats_monstre = adversaire.force |
||||||
|
|
||||||
|
if crit_personnage: |
||||||
|
degats_personnage *= 2 |
||||||
|
print(f"{self.nom} inflige un coup critique ! Les dégâts sont doublés !") |
||||||
|
if crit_monstre: |
||||||
|
degats_monstre *= 2 |
||||||
|
print(f"{adversaire.nom} inflige un coup critique ! Les dégâts sont doublés !") |
||||||
|
|
||||||
|
# Comparer les scores |
||||||
|
if score_personnage == score_monstre: |
||||||
|
# Les deux scores sont identiques |
||||||
|
self.subir_degats(1) |
||||||
|
adversaire.subir_degats(1) |
||||||
|
message = f"Égalité ! {self.nom} et {adversaire.nom} subissent chacun 1 point de dégâts." |
||||||
|
print(message) |
||||||
|
if self.est_hs() and adversaire.est_hs(): |
||||||
|
return ("MP", message) |
||||||
|
elif self.est_hs(): |
||||||
|
return ("P", f"{self.nom} est HS ! {adversaire.nom} reste en vie.") |
||||||
|
elif adversaire.est_hs(): |
||||||
|
return ("M", f"{adversaire.nom} est HS ! {self.nom} reste en vie.") |
||||||
|
else: |
||||||
|
return ("x", message) |
||||||
|
elif score_personnage > score_monstre: |
||||||
|
# Le personnage a gagné le combat |
||||||
|
adversaire.subir_degats(degats_personnage) |
||||||
|
message = f"{self.nom} inflige {degats_personnage} dégâts à {adversaire.nom}." |
||||||
|
print(message) |
||||||
|
if adversaire.est_hs(): |
||||||
|
return ("M", f"{adversaire.nom} est HS ! {self.nom} reste en vie.") |
||||||
|
else: |
||||||
|
return ("x", message) |
||||||
|
else: |
||||||
|
# Le monstre a gagné le combat |
||||||
|
self.subir_degats(degats_monstre) |
||||||
|
message = f"{adversaire.nom} inflige {degats_monstre} dégâts à {self.nom}." |
||||||
|
print(message) |
||||||
|
if self.est_hs(): |
||||||
|
return ("P", f"{self.nom} est HS ! {adversaire.nom} reste en vie.") |
||||||
|
else: |
||||||
|
return ("x", message) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': |
||||||
|
a = Monstre("Squelette", "Un squelette semblant bouger seul et muni d'une épée.", "squelette.png") |
||||||
|
b = Monstre("Yone", "Yone atroce de malone qui pue sa mère", "Yone.png") |
||||||
|
c = Monstre("Viego", "Viego trop fort d'alexis lvl master", "Viego.png") |
Loading…
Reference in new issue