89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
import os
|
|
import sys
|
|
from enum import Enum
|
|
|
|
from character_builder import CharacterBuilder
|
|
from level_one 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 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 : "))
|
|
for action in actions_autorisees:
|
|
if action.code == choix:
|
|
return action
|
|
|
|
print("Mauvais choix")
|
|
except ValueError:
|
|
print("Veuillez saisir un nombre.")
|
|
|
|
|
|
# Exemple d'utilisation
|
|
if __name__ == "__main__":
|
|
loaded_character = CharacterBuilder.load_character("Jamin")
|
|
if not loaded_character:
|
|
sys.exit(-1)
|
|
|
|
print(loaded_character)
|
|
|
|
level = Level(2, loaded_character)
|
|
player = level.player
|
|
rooms = level.rooms
|
|
number_room = len(rooms)
|
|
print(f"Nombre de pièce dans le donjon : {number_room}")
|
|
|
|
while level.exit_level:
|
|
os.system('cls' if os.name == 'nt' else 'clear')
|
|
match action_menu([Action.PIECE_SUIVANTE, Action.QUITTER]):
|
|
case Action.PIECE_SUIVANTE:
|
|
if level.current_room_index >= number_room:
|
|
print("fin du donjon !")
|
|
break
|
|
room = rooms[level.current_room_index]
|
|
print(f"Pièce actuelle : {level.current_room_index}")
|
|
if room is not None:
|
|
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, player)
|
|
if player.current_pv <= 0:
|
|
print("!!!!!!!!! Joueur mort !!!!!!!!!!")
|
|
break
|
|
if mob.current_pv == 0:
|
|
print(f"Le {mob.name} est mort !!")
|
|
case Action.FUIR:
|
|
print("Tu fuis la pièce")
|
|
else:
|
|
print("\n ------ Pièce vide ------ \n")
|
|
player.current_pv = player.max_pv
|
|
level.current_room_index += 1
|
|
case Action.QUITTER:
|
|
level.exit_level = False
|
|
print(f"Au revoir {player.name} !")
|