🎨 parameterized action menu
This commit is contained in:
@@ -1,16 +1,45 @@
|
||||
import os
|
||||
from enum import Enum
|
||||
|
||||
from character_builder import CharacterBuilder
|
||||
from level_one import Level
|
||||
import os
|
||||
|
||||
|
||||
def action_menu():
|
||||
""" Menu Action du niveau """
|
||||
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")
|
||||
print("Pièce Suivante :\t\t 1")
|
||||
print("Combat : \t\t\t 2")
|
||||
print("Fuir : \t\t\t\t 3")
|
||||
print("Quitter :\t\t\t 4")
|
||||
return int(input("\nChoix : "))
|
||||
|
||||
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
|
||||
@@ -27,8 +56,8 @@ if __name__ == "__main__":
|
||||
|
||||
while level.exit_level:
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
match action_menu():
|
||||
case 1:
|
||||
match action_menu([Action.PIECE_SUIVANTE, Action.QUITTER]):
|
||||
case Action.PIECE_SUIVANTE:
|
||||
if level.current_room_index >= number_room:
|
||||
print("fin du donjon !")
|
||||
break
|
||||
@@ -37,22 +66,20 @@ if __name__ == "__main__":
|
||||
if room is not None:
|
||||
for mob in room:
|
||||
print(f"Un {mob.name} est devant toi !")
|
||||
match action_menu():
|
||||
case 2:
|
||||
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 3:
|
||||
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 4:
|
||||
case Action.QUITTER:
|
||||
level.exit_level = False
|
||||
print(f"Au revoir {player.name} !")
|
||||
case _:
|
||||
print("Mauvais choix")
|
||||
|
||||
Reference in New Issue
Block a user