diff --git a/roboc/configuration.py b/roboc/configuration.py index e2d2d54..365c77a 100644 --- a/roboc/configuration.py +++ b/roboc/configuration.py @@ -75,9 +75,8 @@ MSG_END_GAME = "Fin du jeu." MSG_HELP = "Voici les commandes disponibles:\n" MSG_SELECTED_MAP = "Vous avez fait le choix #{}, la carte «{}»." -# VARIABLES -maps_name_list = list() # liste des maps proposees a l'utilisateur -user_select_backup = str() # choix utilisateur: la sauvegarde +MAPS_NAME_LIST = list() # liste des maps proposees a l'utilisateur +USER_SELECT_BACKUP = str() # choix utilisateur: la sauvegarde # FONCTIONS @@ -104,12 +103,12 @@ def choose_maps_menu(): print(MSG_AVAIBLE_MAP) i = 0 - for maps_name in maps_name_list: + for maps_name in MAPS_NAME_LIST: print("\t[{}] - {}".format(i, maps_name)) i += 1 # Choix de la carte par l'utilisateur - while user_select_map_id > len(maps_name_list) or user_select_map_id < 0: + while user_select_map_id > len(MAPS_NAME_LIST) or user_select_map_id < 0: user_select_map_id = input(MSG_CHOOSE_MAP) try: user_select_map_id = int(user_select_map_id) @@ -118,19 +117,19 @@ def choose_maps_menu(): user_select_map_id = -1 continue - if user_select_map_id > len(maps_name_list) or \ + if user_select_map_id > len(MAPS_NAME_LIST) or \ user_select_map_id < 0: print(ERR_PLAGE) cls() # vide l'ecran de la console print(MSG_SELECTED_MAP.format( user_select_map_id, - maps_name_list[user_select_map_id] + MAPS_NAME_LIST[user_select_map_id] )) # Fichier carte a recuperer map_file = MAP_DIRECTORY + \ - maps_name_list[user_select_map_id] + \ + MAPS_NAME_LIST[user_select_map_id] + \ MAP_EXTENTION # instenciation de la carte choisie diff --git a/roboc/map.py b/roboc/map.py index 9a7dbbe..5dc6e55 100644 --- a/roboc/map.py +++ b/roboc/map.py @@ -155,7 +155,7 @@ class Map: if len(move[1:]) > 0: # on recupere les caractere suivants (dist) try: goal = int(move[1:]) - except ValueError as except_detail: + except ValueError: return 0 else: # si pas de chiffre, on avance d'une seule unite goal = 1 @@ -237,7 +237,5 @@ class Map: if __name__ == "__main__": - """ Starting doctests """ - import doctest doctest.testmod() diff --git a/roboc/roboc.py b/roboc/roboc.py index 916045a..2b4c720 100644 --- a/roboc/roboc.py +++ b/roboc/roboc.py @@ -18,25 +18,25 @@ import os import pickle from configuration import BACKUP_FILE, choose_maps_menu, cls, COMMANDS, \ COMMANDS_LABEL, DIRECTIONS, DIRECTIONS_LABEL, get_msg_list, \ - MAP_DIRECTORY, MAP_EXTENTION, maps_name_list, MOVE_STATUS, \ + MAP_DIRECTORY, MAP_EXTENTION, MAPS_NAME_LIST, MOVE_STATUS, \ MOVE_STATUS_MSG, MSG_AVAIBLE_BACKUP, MSG_BACKUP_DONE, MSG_BACKUP_GAME, \ MSG_CHOOSE_MOVE, MSG_DISCLAMER, MSG_END_GAME, MSG_HELP, MSG_NO_YES, \ - MSG_START_GAME, user_select_backup + MSG_START_GAME, USER_SELECT_BACKUP # DEBUT DU JEU # Recuperation de la liste des cartes try: - maps_avaiable = os.listdir(MAP_DIRECTORY) + MAPS_AVAIBLE = os.listdir(MAP_DIRECTORY) except FileNotFoundError as except_detail: print("FileNotFoundError: «{}»".format(except_detail)) else: - for map_file in maps_avaiable: + for map_file in MAPS_AVAIBLE: filename_len = len(map_file) - len(MAP_EXTENTION) # garde les fichiers avec la bonne extention if map_file[filename_len:] == MAP_EXTENTION: - maps_name_list.append(map_file[: filename_len]) + MAPS_NAME_LIST.append(map_file[: filename_len]) # Affichage du debut de partie cls() # vide l'ecran de la console @@ -45,78 +45,78 @@ print(MSG_DISCLAMER) # Verif si un fichier de sauvegarde est dispo if os.path.isfile(BACKUP_FILE) is True: with open(BACKUP_FILE, 'rb') as backup_file: - backup_map = pickle.Unpickler(backup_file).load() + BACKUP_MAP = pickle.Unpickler(backup_file).load() # On demande si l'utilisateur veut charger la sauvegarde - while user_select_backup not in MSG_NO_YES: - user_select_backup = input( - MSG_AVAIBLE_BACKUP.format(*MSG_NO_YES) - ).lower() + while USER_SELECT_BACKUP not in MSG_NO_YES: + USER_SELECT_BACKUP = input( + MSG_AVAIBLE_BACKUP.format(*MSG_NO_YES) + ).lower() # utilisateur veut la sauvegarde - if user_select_backup == MSG_NO_YES[1]: - current_map = backup_map + if USER_SELECT_BACKUP == MSG_NO_YES[1]: + CURRENT_MAP = BACKUP_MAP else: - current_map = choose_maps_menu() + CURRENT_MAP = choose_maps_menu() else: - current_map = choose_maps_menu() + CURRENT_MAP = choose_maps_menu() # DEBUT DE BOUCLE DE TOUR DE JEU # Affichage de la carte tant que status == True -while current_map.status: +while CURRENT_MAP.status: # Affiche la carte et le message - current_map.map_print() - print(current_map.status_message) + CURRENT_MAP.map_print() + print(CURRENT_MAP.status_message) # Demande a l'utilisateur son choix du deplacement user_move = input(MSG_CHOOSE_MOVE.format( COMMANDS[1], COMMANDS_LABEL[1]) - ).upper() + ).upper() cls() # vide l'ecran de la console # Traitement de la commande utilisateur if user_move == COMMANDS[0]: # quitter - current_map.status = False + CURRENT_MAP.status = False # Le premier tour n'a pas ete joue, pas de sauvegarde faite - if current_map.status_message != MSG_START_GAME: - current_map.status_message = MSG_BACKUP_DONE + if CURRENT_MAP.status_message != MSG_START_GAME: + CURRENT_MAP.status_message = MSG_BACKUP_DONE else: - current_map.status_message = "" + CURRENT_MAP.status_message = "" elif user_move == COMMANDS[1]: # Affiche l'aide - current_map.status_message = MSG_HELP + CURRENT_MAP.status_message = MSG_HELP # liste les directions - current_map.status_message += get_msg_list( + CURRENT_MAP.status_message += get_msg_list( DIRECTIONS, DIRECTIONS_LABEL ) # liste les commandes - current_map.status_message += get_msg_list(COMMANDS, COMMANDS_LABEL) + CURRENT_MAP.status_message += get_msg_list(COMMANDS, COMMANDS_LABEL) else: # Traitement du deplacement - status = current_map.move_to(user_move) + status = CURRENT_MAP.move_to(user_move) message = MOVE_STATUS_MSG[MOVE_STATUS[status]].format(user_move) # La sortie est atteinte, fin de la boucle if MOVE_STATUS[status] == 'exit': - current_map.status = False - current_map.status_message = message + CURRENT_MAP.status = False + CURRENT_MAP.status_message = message else: # sinon on sauvegarde la partie avant de refaire un tour - current_map.status_message = MSG_BACKUP_GAME + CURRENT_MAP.status_message = MSG_BACKUP_GAME with open(BACKUP_FILE, 'wb') as backup_file: - pickle.Pickler(backup_file).dump(current_map) + pickle.Pickler(backup_file).dump(CURRENT_MAP) - current_map.status_message = message + CURRENT_MAP.status_message = message # fin de la boucle de tour -if current_map.status is False: - print(current_map.status_message) +if CURRENT_MAP.status is False: + print(CURRENT_MAP.status_message) # Fin de partie print(MSG_END_GAME) -current_map.map_print() +CURRENT_MAP.map_print()