cli & console output #4

Merged
bbaudouin merged 9 commits from ux into develop 2026-07-22 07:57:32 +01:00
3 changed files with 18 additions and 0 deletions
Showing only changes of commit d02b48b2b0 - Show all commits
+7
View File
@@ -6,13 +6,17 @@ from .level import Level
from .menu import Action, action_menu
from .mob import BaseMob, load_character
logger = logging.getLogger(__name__)
def play_room(room: list[BaseMob], level: Level) -> int:
if room is None:
logger.info('Empty room')
print("\n ------ Pièce vide ------ \n")
return 1
for mob in room:
logger.info('Meet mob %s', mob.name)
print(f"Un {mob.name} est devant toi !")
match action_menu([Action.COMBAT, Action.FUIR]):
case Action.COMBAT:
@@ -35,12 +39,15 @@ def play_donjon(level: Level) -> None:
match action_menu([Action.PIECE_SUIVANTE, Action.QUITTER]):
case Action.PIECE_SUIVANTE:
if level.current_room_index >= len(level.rooms):
logger.info('Exiting last room')
print("fin du donjon !")
break
logger.info('Entering next room')
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
logger.info('Leaving game')
print(f"Au revoir {level.player.name} !")
+10
View File
@@ -1,6 +1,9 @@
import logging
import os
from enum import Enum
logger = logging.getLogger(__name__)
class Action(Enum):
PIECE_SUIVANTE = (1, "Pièce suivante")
@@ -26,6 +29,10 @@ def action_menu(actions_autorisees: list[Action] = None) -> Action:
actions_autorisees = list(Action) if actions_autorisees is None else actions_autorisees
logger.debug('Show action menu')
for action in actions_autorisees:
logger.debug('Action %s - "%s"', action.code, action.libelle)
while True:
print("\n------ Menu Action ------\n")
@@ -37,9 +44,12 @@ def action_menu(actions_autorisees: list[Action] = None) -> Action:
clear_console()
for action in actions_autorisees:
if action.code == choix:
logger.info('User selected action %s - "%s"', action.code, action.libelle)
return action
print("Mauvais choix")
except ValueError:
clear_console()
print("Veuillez saisir un nombre.")
logger.info('Bad input')
+1
View File
@@ -38,6 +38,7 @@ def save_character(character: BaseMob) -> str:
def load_character(name: str) -> BaseMob | None:
"""Charge un personnage à partir d'un fichier JSON."""
logger.debug('Loading character %s', name)
filename = name + ".json"
if not os.path.exists(filename):
logger.error(f"Erreur : Le fichier {filename} n'existe pas.")