🔊 add some logs
This commit is contained in:
@@ -6,13 +6,17 @@ from .level import Level
|
|||||||
from .menu import Action, action_menu
|
from .menu import Action, action_menu
|
||||||
from .mob import BaseMob, load_character
|
from .mob import BaseMob, load_character
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def play_room(room: list[BaseMob], level: Level) -> int:
|
def play_room(room: list[BaseMob], level: Level) -> int:
|
||||||
if room is None:
|
if room is None:
|
||||||
|
logger.info('Empty room')
|
||||||
print("\n ------ Pièce vide ------ \n")
|
print("\n ------ Pièce vide ------ \n")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
for mob in room:
|
for mob in room:
|
||||||
|
logger.info('Meet mob %s', mob.name)
|
||||||
print(f"Un {mob.name} est devant toi !")
|
print(f"Un {mob.name} est devant toi !")
|
||||||
match action_menu([Action.COMBAT, Action.FUIR]):
|
match action_menu([Action.COMBAT, Action.FUIR]):
|
||||||
case Action.COMBAT:
|
case Action.COMBAT:
|
||||||
@@ -35,12 +39,15 @@ def play_donjon(level: Level) -> None:
|
|||||||
match action_menu([Action.PIECE_SUIVANTE, Action.QUITTER]):
|
match action_menu([Action.PIECE_SUIVANTE, Action.QUITTER]):
|
||||||
case Action.PIECE_SUIVANTE:
|
case Action.PIECE_SUIVANTE:
|
||||||
if level.current_room_index >= len(level.rooms):
|
if level.current_room_index >= len(level.rooms):
|
||||||
|
logger.info('Exiting last room')
|
||||||
print("fin du donjon !")
|
print("fin du donjon !")
|
||||||
break
|
break
|
||||||
|
logger.info('Entering next room')
|
||||||
level.current_room_index += play_room(level.rooms[level.current_room_index], level)
|
level.current_room_index += play_room(level.rooms[level.current_room_index], level)
|
||||||
level.player.current_pv = level.player.max_pv
|
level.player.current_pv = level.player.max_pv
|
||||||
case Action.QUITTER:
|
case Action.QUITTER:
|
||||||
level.exit_level = False
|
level.exit_level = False
|
||||||
|
logger.info('Leaving game')
|
||||||
print(f"Au revoir {level.player.name} !")
|
print(f"Au revoir {level.player.name} !")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Action(Enum):
|
class Action(Enum):
|
||||||
PIECE_SUIVANTE = (1, "Pièce suivante")
|
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
|
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:
|
while True:
|
||||||
print("\n------ Menu Action ------\n")
|
print("\n------ Menu Action ------\n")
|
||||||
|
|
||||||
@@ -37,9 +44,12 @@ def action_menu(actions_autorisees: list[Action] = None) -> Action:
|
|||||||
clear_console()
|
clear_console()
|
||||||
for action in actions_autorisees:
|
for action in actions_autorisees:
|
||||||
if action.code == choix:
|
if action.code == choix:
|
||||||
|
logger.info('User selected action %s - "%s"', action.code, action.libelle)
|
||||||
return action
|
return action
|
||||||
|
|
||||||
print("Mauvais choix")
|
print("Mauvais choix")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
clear_console()
|
clear_console()
|
||||||
print("Veuillez saisir un nombre.")
|
print("Veuillez saisir un nombre.")
|
||||||
|
|
||||||
|
logger.info('Bad input')
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ def save_character(character: BaseMob) -> str:
|
|||||||
|
|
||||||
def load_character(name: str) -> BaseMob | None:
|
def load_character(name: str) -> BaseMob | None:
|
||||||
"""Charge un personnage à partir d'un fichier JSON."""
|
"""Charge un personnage à partir d'un fichier JSON."""
|
||||||
|
logger.debug('Loading character %s', name)
|
||||||
filename = name + ".json"
|
filename = name + ".json"
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
logger.error(f"Erreur : Le fichier {filename} n'existe pas.")
|
logger.error(f"Erreur : Le fichier {filename} n'existe pas.")
|
||||||
|
|||||||
Reference in New Issue
Block a user