From 665a0f4b37edfde09d422b77dc1122c2df7cfca6 Mon Sep 17 00:00:00 2001 From: Fred Z Date: Thu, 15 Feb 2018 11:00:12 +0100 Subject: [PATCH] PEP8 conformity|TP_3.9|ROBOC --- roboc/configuration.py | 19 +++++++++++++------ roboc/map.py | 18 +++++++++++------- roboc/roboc.py | 18 ++++++++++++------ 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/roboc/configuration.py b/roboc/configuration.py index 9e23ad6..e611935 100644 --- a/roboc/configuration.py +++ b/roboc/configuration.py @@ -35,7 +35,7 @@ ERR_UNKNOW = ERR_ + "personne n'est censé arriver ici…" MIN_MAP_SIDE = 3 MSG_DISCLAMER = "Bienvenue dans Roboc." -MSG_AVAIBLE_BACKUP = "Une sauvegarde est dispo, voulez-vous la charger? ({}/{}) " +MSG_AVAIBLE_BACKUP = "Sauvegarde dispo, voulez-vous la charger? ({}/{}) " MSG_AVAIBLE_MAP = "Cartes disponible: " MSG_BACKUP_DONE = "La partie a été sauvegardée." MSG_BACKUP_GAME = "Partie sauvegardé" @@ -51,16 +51,21 @@ DEBUG = False # VARIABLES + maps_name_list = list() # liste des maps proposees a l'utilisateur user_select_backup = str() # choix utilisateur: la sauvegarde + # FUNCTIONS + + def cls(): """ Efface l'historique de la console """ import os os.system('clear') return + def choose_maps_menu(): """ Affiche le menu de selection des cartes """ from map import Map @@ -92,13 +97,15 @@ def choose_maps_menu(): print(ERR_PLAGE) cls() # clear screen - print(MSG_SELECTED_MAP.format(user_select_map_id, - maps_name_list[user_select_map_id])) + print(MSG_SELECTED_MAP.format( + 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] + \ - MAP_EXTENTION + maps_name_list[user_select_map_id] + \ + MAP_EXTENTION # instenciation de la carte choisie - return Map(map_file) \ No newline at end of file + return Map(map_file) diff --git a/roboc/map.py b/roboc/map.py index c60edfb..947249a 100644 --- a/roboc/map.py +++ b/roboc/map.py @@ -6,11 +6,12 @@ Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/ Ce fichier fait partie du projet `roboc` """ - -import os -from configuration import * - # TODO01 sortir les doctests +import os +from configuration import DIRECTIONS, ERR_MAP_FILE, ERR_MAP_ROBO, \ + MIN_MAP_SIDE, ERR_MAP_SIZE, ERR_UNKNOW, MAZE_ELEMENTS + + class Map: """ Classe gerant les cartes disponibles et la carte utilisee en cours @@ -156,7 +157,8 @@ class Map: steps = 0 # direction non conforme - # TODO13 UnboundLocalError: local variable 'direction' referenced before assignment + # TODO13 UnboundLocalError: local variable 'direction' \ + # referenced before assignment if direction not in DIRECTIONS: move_status = 0 @@ -189,7 +191,8 @@ class Map: self._element_under_robo = MAZE_ELEMENTS['void'] # Traitement en fonction de la case du prochain pas - # TODO11 next_char = self._data_text[next_position] : IndexError: string index out of range + # TODO11 next_char = self._data_text[next_position] : \ + # IndexError: string index out of range next_char = self._data_text[next_position] if next_char == MAZE_ELEMENTS['wall']: move_status = 1 @@ -230,8 +233,9 @@ class Map: txt = self._data_text self._data_text = txt[:pos] + element + txt[pos + 1:] + if __name__ == "__main__": """ Starting doctests """ import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod() diff --git a/roboc/roboc.py b/roboc/roboc.py index eb97f4f..88e86ab 100644 --- a/roboc/roboc.py +++ b/roboc/roboc.py @@ -13,13 +13,17 @@ Jeu permettant de controler un robot dans un labyrinthe C'est un labyrinthe forme d'obstacles: des murs, des portes et au moins une sortie. Arrive sur ce point, la partie est terminee. -Source: https://openclassrooms.com/courses/apprenez-a-programmer-en-python/exercises/180 +Source: +https://openclassrooms.com/courses/apprenez-a-programmer-en-python/exercises/180 """ import os import pickle -from map import Map -from configuration import * +# 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 # DEBUT DU JEU @@ -34,7 +38,7 @@ else: # 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]) cls() # clear screen # Affichage du debut de partie @@ -47,7 +51,9 @@ if os.path.isfile(BACKUP_FILE) is True: # 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() + user_select_backup = input( + MSG_AVAIBLE_BACKUP.format(*MSG_NO_YES) + ).lower() if user_select_backup == MSG_NO_YES[1]: current_map = backup_map @@ -115,4 +121,4 @@ current_map.map_print() if __name__ == "__main__": """ Starting doctests """ import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod()