🏗️ ♻️ restructuration du projet et refactoring #3
+1
-45
@@ -1,53 +1,9 @@
|
|||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
from .base_mob import BaseMob
|
from .base_mob import BaseMob
|
||||||
from .character_builder import CharacterBuilder
|
from .character_builder import CharacterBuilder
|
||||||
from .level import Level
|
from .level import Level
|
||||||
|
from .menu import Action, action_menu
|
||||||
|
|
||||||
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:
|
def play_room(room: list[BaseMob], level: Level) -> int:
|
||||||
|
|||||||
+42
-22
@@ -1,25 +1,45 @@
|
|||||||
|
import os
|
||||||
# def main_loop(breaker:bool):
|
from enum import Enum
|
||||||
# pass
|
|
||||||
|
|
||||||
# def menu ():
|
|
||||||
# print("Nouvelle partie :\t1")
|
|
||||||
# print("Charger :\t\t2")
|
|
||||||
# print("Option :\t\t3")
|
|
||||||
# print("Quitter :\t\t4")
|
|
||||||
# return int(input("Choix : "))
|
|
||||||
|
|
||||||
|
|
||||||
# choix = menu()
|
class Action(Enum):
|
||||||
|
PIECE_SUIVANTE = (1, "Pièce suivante")
|
||||||
|
COMBAT = (2, "Combat")
|
||||||
|
FUIR = (3, "Fuir")
|
||||||
|
QUITTER = (4, "Quitter")
|
||||||
|
|
||||||
# match choix:
|
@property
|
||||||
# case 1:
|
def code(self):
|
||||||
# print("Nouvelle partie")
|
return self.value[0]
|
||||||
# case 2:
|
|
||||||
# print("Charger")
|
@property
|
||||||
# case 3:
|
def libelle(self):
|
||||||
# print("Option")
|
return self.value[1]
|
||||||
# case 4:
|
|
||||||
# print("Quitter")
|
|
||||||
# case _:
|
def clear_console() -> None:
|
||||||
# print("Mauvais choix")
|
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.")
|
||||||
|
|||||||
Reference in New Issue
Block a user