From 765c477315d5417d973da87e41e939ef07a72a6d Mon Sep 17 00:00:00 2001 From: Fred Z Date: Wed, 14 Feb 2018 17:21:33 +0100 Subject: [PATCH] =?UTF-8?q?Boucle=20de=20jeu=20op=C3=A9rationnelle|TP=5F3.?= =?UTF-8?q?9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roboc/configuration.py | 6 +++++- roboc/map.py | 7 ++++++- roboc/roboc.py | 29 +++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/roboc/configuration.py b/roboc/configuration.py index e62de28..ff238c3 100644 --- a/roboc/configuration.py +++ b/roboc/configuration.py @@ -28,13 +28,17 @@ ERR_MAP_SIZE = ERR_ + "carte «{}», dimensions incorrecte: «{} x {}»" ERR_MAP_ROBO = ERR_ + "robo est introuvable sur la carte «{}»!" ERR_PLAGE = ERR_ + "saisir un nombre dans la plage indiquée! " 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_MAP = "Cartes disponible: " MSG_CHOOSE_MAP = "Choississez un numéro de carte: " -MSG_CHOOSE_MOVE = "Votre deplacement (h pour l'aide): " +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/map.py b/roboc/map.py index 9f64ae2..9305432 100644 --- a/roboc/map.py +++ b/roboc/map.py @@ -145,7 +145,12 @@ class Map: :return: key in MOVE_STATUS """ # decompose le mouvement - direction = move[0] + try: + direction = move[0] + except IndexError as except_detail: + # print("IndexError: «{}»".format(except_detail)) + return 0 + try: goal = int(move[1:]) except ValueError as except_detail: diff --git a/roboc/roboc.py b/roboc/roboc.py index 6114c1b..9b103af 100644 --- a/roboc/roboc.py +++ b/roboc/roboc.py @@ -85,24 +85,45 @@ map_file = MAP_DIRECTORY + \ current_map = Map(map_file) # DEBUT DE BOUCLE DE TOUR DE JEU -# TODO : clear screen # Affichage de la carte et de la position de jeu -if current_map.status: +while current_map.status: + # TODO : clear screen current_map.map_print() # choix du deplacement user_select_move = input(MSG_CHOOSE_MOVE) # traitement du deplacement - current_map.move_to(user_select_move) + move_status_id = current_map.move_to(user_select_move) -else: + if MOVE_STATUS[move_status_id] == 'ok': + print('MSG_OK') + + 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': + current_map.status = False + current_map.status_message = MSG_EXIT + + else : # juste au cas ou… + print(ERR_UNKNOW) + +if current_map.status is False: print(current_map.status_message) # fin de la boucle de tour # Fin de partie +print(MSG_END_GAME) + if __name__ == "__main__": """ Starting doctests """