From 7a91f4917d4337699d3df8e3a55b924a6245eaaf Mon Sep 17 00:00:00 2001 From: Fred Z Date: Thu, 15 Feb 2018 11:00:12 +0100 Subject: [PATCH] DONE09 msg de status dans un dict|TP_3.9|ROBOC Permet de supprimmer les conditions verifiant le status d'un deplacement pour afficher le bon message. La valeur du statut en cours est utilisee pour recuperer le message lui correspondant. --- roboc/configuration.py | 8 +++++++- roboc/roboc.py | 28 +++++++++------------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/roboc/configuration.py b/roboc/configuration.py index e611935..f68d22c 100644 --- a/roboc/configuration.py +++ b/roboc/configuration.py @@ -24,6 +24,12 @@ MAZE_ELEMENTS = {'wall': 'O', # elements dispo dans le labyrinthe 'void': ' '} # Issue possible d'un mouvement, garder le OK toujours en fin de liste MOVE_STATUS = ['bad', 'wall', 'exit', 'door', 'ok'] +MOVE_STATUS_MSG = {'bad': "Le déplacement «{}» n'est pas autorisé.", + 'wall': "Le déplacement est stoppé par un mur.", + 'exit': "Vous êtes sortit du labyrinte", + 'door': "Vous passez une porte", + 'ok': "Jusqu'ici, tout va bien…" +} ERR_ = "#!@?# Oups… " ERR_MAP_FILE = ERR_ + "carte «{}» inaccessible!" @@ -34,6 +40,7 @@ ERR_SAISIE = ERR_ + "saisir un nombre! " ERR_UNKNOW = ERR_ + "personne n'est censé arriver ici…" MIN_MAP_SIDE = 3 + MSG_DISCLAMER = "Bienvenue dans Roboc." MSG_AVAIBLE_BACKUP = "Sauvegarde dispo, voulez-vous la charger? ({}/{}) " MSG_AVAIBLE_MAP = "Cartes disponible: " @@ -44,7 +51,6 @@ MSG_CHOOSE_MOVE = "Votre deplacement: " MSG_DOOR = "Vous passez une porte" MSG_SELECTED_MAP = "Vous avez fait le choix #{}, la carte «{}»." MSG_END_GAME = "Fin de la partie." -MSG_EXIT = "Vous avez atteint la sortie!" DEBUG = False diff --git a/roboc/roboc.py b/roboc/roboc.py index 88e86ab..ae28fe8 100644 --- a/roboc/roboc.py +++ b/roboc/roboc.py @@ -22,8 +22,8 @@ import pickle # from map import Map from configuration import BACKUP_FILE, choose_maps_menu, cls, COMMANDS, \ ERR_UNKNOW, MAP_DIRECTORY, MAP_EXTENTION, maps_name_list, MOVE_STATUS, \ - MSG_AVAIBLE_BACKUP, MSG_BACKUP_DONE, MSG_CHOOSE_MOVE, MSG_DISCLAMER, \ - MSG_END_GAME, MSG_EXIT, MSG_NO_YES, user_select_backup + MOVE_STATUS_MSG, MSG_AVAIBLE_BACKUP, MSG_BACKUP_DONE, MSG_CHOOSE_MOVE, \ + MSG_DISCLAMER, MSG_END_GAME, MSG_NO_YES, user_select_backup # DEBUT DU JEU @@ -86,26 +86,16 @@ while current_map.status: else: # traitement du deplacement move_status_id = current_map.move_to(user_select_move) + current_map.status_message = \ + MOVE_STATUS_MSG[MOVE_STATUS[move_status_id]].format(user_select_move) - # TODO09 ranger les status dans un dict('ok': MSG_OK, …) - if MOVE_STATUS[move_status_id] == 'ok': - print('MSG_OK') + # La sortie n'est pas atteinte, la boucle continue + if MOVE_STATUS[move_status_id] != 'exit': + print(current_map.status_message) - elif MOVE_STATUS[move_status_id] == 'bad': - print('MSG_BAD') - - elif MOVE_STATUS[move_status_id] == 'wall': - print('MSG_WALL') - - elif MOVE_STATUS[move_status_id] == 'door': - print('MSG_DOOR') - - elif MOVE_STATUS[move_status_id] == 'exit': + # La sortie est atteinte, fin de la boucle + else: current_map.status = False - current_map.status_message = MSG_EXIT - - else: # juste au cas ou… - raise NotImplementedError(ERR_UNKNOW) # TODO10 rester dans la boucle si la carte n'est pas conforme if current_map.status is False: