106 lines
2.9 KiB
Python
106 lines
2.9 KiB
Python
import os
|
|
import sys
|
|
from enum import Enum
|
|
|
|
from base_mob import BaseMob
|
|
from character_builder import CharacterBuilder
|
|
from level import Level
|
|
|
|
|
|
class Action(Enum):
|
|
PIECE_SUIVANTE = (1, "Pièce suivante")
|
|
COMBAT = (2, "Combat")
|
|
FUIR = (3, "Fuir")
|
|
QUITTER = (4, "Quitter")
|
|
|
|
@property
|
|
def code(self):
|
|
return self.value[0]
|
|
|
|
@property
|
|
def libelle(self):
|
|
return self.value[1]
|
|
|
|
|
|
def clear_console() -> None:
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
|
|
|
|
def action_menu(actions_autorisees: list[Action] = None) -> Action:
|
|
"""Affiche le menu et retourne une action valide."""
|
|
|
|
actions_autorisees = list(Action) if actions_autorisees is None else actions_autorisees
|
|
|
|
while True:
|
|
print("\n------ Menu Action ------\n")
|
|
|
|
for action in actions_autorisees:
|
|
print(f"{action.libelle:<20} : {action.code}")
|
|
|
|
try:
|
|
choix = int(input("\nChoix : "))
|
|
clear_console()
|
|
for action in actions_autorisees:
|
|
if action.code == choix:
|
|
return action
|
|
|
|
print("Mauvais choix")
|
|
except ValueError:
|
|
clear_console()
|
|
print("Veuillez saisir un nombre.")
|
|
|
|
|
|
def play_room(room: list[BaseMob], level: Level) -> int:
|
|
if room is None:
|
|
print("\n ------ Pièce vide ------ \n")
|
|
return 1
|
|
|
|
for mob in room:
|
|
print(f"Un {mob.name} est devant toi !")
|
|
match action_menu([Action.COMBAT, Action.FUIR]):
|
|
case Action.COMBAT:
|
|
level.combat(mob, level.player)
|
|
if level.player.current_pv <= 0:
|
|
print("!!!!!!!!! Joueur mort !!!!!!!!!!")
|
|
sys.exit(0)
|
|
if mob.current_pv == 0:
|
|
print(f"Le {mob.name} est mort !!")
|
|
case Action.FUIR:
|
|
print("Tu fuis la pièce")
|
|
return 0
|
|
|
|
return 1
|
|
|
|
|
|
def play_donjon(level: Level) -> None:
|
|
while level.exit_level:
|
|
print(f"Pièce actuelle : {level.current_room_index}")
|
|
match action_menu([Action.PIECE_SUIVANTE, Action.QUITTER]):
|
|
case Action.PIECE_SUIVANTE:
|
|
if level.current_room_index >= len(level.rooms):
|
|
print("fin du donjon !")
|
|
break
|
|
level.current_room_index += play_room(level.rooms[level.current_room_index], level)
|
|
level.player.current_pv = level.player.max_pv
|
|
case Action.QUITTER:
|
|
level.exit_level = False
|
|
print(f"Au revoir {level.player.name} !")
|
|
|
|
|
|
def app() -> None:
|
|
loaded_character = CharacterBuilder.load_character(sys.argv[1] if len(sys.argv) > 1 else "Jamin")
|
|
if not loaded_character:
|
|
sys.exit(-1)
|
|
|
|
print(loaded_character)
|
|
|
|
level = Level(2, loaded_character)
|
|
print(f"Nombre de pièce dans le donjon : {len(level.rooms)}")
|
|
|
|
play_donjon(level)
|
|
|
|
|
|
# Exemple d'utilisation
|
|
if __name__ == "__main__":
|
|
app()
|