Dorian.D
1 year ago
1 changed files with 155 additions and 0 deletions
@ -0,0 +1,155 @@
|
||||
import random as rd |
||||
import time |
||||
|
||||
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_max = 5 |
||||
self.endurance = self.endurance_max |
||||
self.force = 2 |
||||
self.courage = rd.randint(1,10) |
||||
|
||||
if "Squelette" in self.nom: |
||||
self.habilite = rd.randint(1,10) |
||||
self.endurance = rd.randint(1,10) |
||||
self.force = rd.randint(1,2) |
||||
self.courage = rd.randint(1,10) |
||||
|
||||
def modifier_endurance(self:'Monstre', modificateur): |
||||
endurance_modifie = self.endurance + modificateur |
||||
if endurance_modifie < 0: |
||||
self.endurance = 0 |
||||
elif endurance_modifie > self.endurance_max: |
||||
self.endurance = self.endurance_max |
||||
else: |
||||
self.endurance = endurance_modifie |
||||
|
||||
def subir_degats(self:'Monstre', degats:int) -> None: |
||||
if degats > 0: |
||||
self.modifier_endurance(-degats) |
||||
|
||||
|
||||
def get_description(self:'Monstre') -> str: |
||||
return self.dsc |
||||
|
||||
def get_carac(self:'Montres') -> str: |
||||
return f"{self.nom} H{self.habilite} E{self.endurance} F{self.force} C{self.courage}" |
||||
|
||||
def est_hs(self:'Monstre') -> bool: |
||||
if self.endurance <= 0: |
||||
return True |
||||
else: |
||||
return False |
||||
|
||||
class Personnage: |
||||
|
||||
def __init__(self, nom='Aucun'): |
||||
|
||||
self.nom = nom |
||||
|
||||
self.habilite = 5 + rd.randint(1,4) |
||||
self.endurance_max = 7 + rd.randint(1,8) |
||||
self.endurance = self.endurance_max |
||||
self.force = 2 |
||||
self.charisme = rd.randint(1,10) |
||||
self.vigilance = rd.randint(1,10) |
||||
self.discretion = False |
||||
self.lieu = None |
||||
self.lieu_precedents = [] |
||||
self.objet = None |
||||
|
||||
def modifier_endurance(self:'Personnage', modificateur): |
||||
endurance_modifie = self.endurance + modificateur |
||||
if endurance_modifie < 0: |
||||
self.endurance = 0 |
||||
elif endurance_modifie > self.endurance_max: |
||||
self.endurance = self.endurance_max |
||||
else: |
||||
self.endurance = endurance_modifie |
||||
|
||||
def subir_degats(self:'Personnage', degats:int) -> None: |
||||
if degats > 0: |
||||
self.modifier_endurance(-degats) |
||||
|
||||
def est_hs(self:'Personnage') -> bool : |
||||
if self.endurance == 0: |
||||
return True |
||||
else: |
||||
return False |
||||
|
||||
def get_carac(self:'Personnage') -> str: |
||||
return f"{self.nom} H{self.habilite} E{self.endurance} F{self.force} C{self.charisme} V{self.vigilance}" |
||||
|
||||
def combattre(self:'Personnage', adversaire:'Monstre') -> tuple: |
||||
""" |
||||
Effectue un combat entre le personnage et un monstre. |
||||
Parameters: |
||||
- self ('Personnage'): L'instance du personnage effectuant l'attaque. |
||||
- adversaire ('Monstre'): L'instance du monstre contre lequel le personnage se bat. |
||||
Returns: |
||||
- tuple: Un tuple contenant le code de résultat et la description du combat. |
||||
Code de Résultat : |
||||
- 'x': Le combat n'est pas encore terminé. |
||||
- 'MP': Les deux participants sont hors combat. |
||||
- 'P': Le personnage est hors combat. |
||||
- 'M': Le monstre est hors combat. |
||||
Description : |
||||
Le combat consiste en plusieurs étapes, où les scores de combat sont comparés, et des dégâts sont infligés en fonction du résultat. |
||||
Les participants peuvent également subir des dégâts critiques ou être hors combat. |
||||
""" |
||||
score_personnage = rd.randint(1, 6) + rd.randint(1, 6) + self.habilite |
||||
score_monstre = rd.randint(1, 6) + rd.randint(1, 6) + adversaire.habilite |
||||
result_code = 'x' |
||||
|
||||
while result_code == 'x': |
||||
if score_personnage == score_monstre: |
||||
self.subir_degats(1) |
||||
adversaire.subir_degats(1) |
||||
result_code = "x" |
||||
result_desc = f"{self.nom} et {adversaire.nom} se blessent mutuellement." |
||||
time.sleep(1) |
||||
print(result_desc) |
||||
elif score_personnage > score_monstre: |
||||
adversaire.subir_degats(self.force) |
||||
result_code = "x" |
||||
result_desc = f"{self.nom} inflige {self.force} points de dégâts au {adversaire.nom}." |
||||
time.sleep(1) |
||||
print(result_desc) |
||||
else: |
||||
self.subir_degats(adversaire.force) |
||||
result_code = "x" |
||||
result_desc = f"{adversaire.nom} inflige {adversaire.force} points de dégâts au {self.nom}." |
||||
time.sleep(0.5) |
||||
print(result_desc) |
||||
if rd.randint(1, 6) == rd.randint(1, 6): |
||||
double_damage = self.force * 2 |
||||
adversaire.subir_degats(double_damage) |
||||
result_desc += f" Coup critique ! {self.nom} inflige {double_damage} points de dégâts supplémentaires au {adversaire.nom}." |
||||
time.sleep(0.5) |
||||
print(result_desc) |
||||
elif self.est_hs() and adversaire.est_hs(): |
||||
result_code = "MP" |
||||
result_desc = f"{self.nom} et {adversaire.nom} sont tous les deux hors combat." |
||||
time.sleep(0.5) |
||||
print(result_desc) |
||||
elif self.est_hs(): |
||||
result_code = "P" |
||||
result_desc = f"{self.nom} est hors combat." |
||||
elif adversaire.est_hs(): |
||||
result_code = "M" |
||||
result_desc = f"{adversaire.nom} est hors combat." |
||||
time.sleep(0.5) |
||||
print(result_desc) |
||||
|
||||
return result_code, result_desc |
||||
|
||||
|
||||
|
||||
h = Personnage("Alice") |
||||
p = Monstre("Squelette", "") |
||||
|
Loading…
Reference in new issue