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