code cleaning & PEP8 checking|TP_3.9|UPDATE roboc.py & map.py
This commit is contained in:
parent
4fdc1856d5
commit
7a32cc88d9
17
roboc/map.py
17
roboc/map.py
|
@ -11,6 +11,7 @@ Ce fichier fait partie du projet `roboc`
|
|||
"""
|
||||
import os
|
||||
|
||||
|
||||
class Map:
|
||||
"""
|
||||
Classe gerant les cartes disponibles et la carte utilisee en cours
|
||||
|
@ -58,10 +59,14 @@ class Map:
|
|||
# Chargement du fichier carte choisi
|
||||
if os.path.isfile(map_file) is True:
|
||||
with open(map_file, "r") as map_data:
|
||||
self._data_text = map_data.read() # Contient le contenu de la carte en texte
|
||||
self._data_list = self._data_text.splitlines() # Contient la carte ligne a ligne
|
||||
self._column_nb = len(self._data_list[0]) # Nombre de colonne de la carte (1ere ligne)
|
||||
self._line_nb = len(self._data_list) # Contient le contenu de la carte en texte
|
||||
# contenu de la carte en texte
|
||||
self._data_text = map_data.read()
|
||||
# contenu de la carte ligne a ligne
|
||||
self._data_list = self._data_text.splitlines()
|
||||
# nbre de colonne de la carte (1ere ligne)
|
||||
self._column_nb = len(self._data_list[0])
|
||||
# nbre de ligne de la carte
|
||||
self._line_nb = len(self._data_list)
|
||||
|
||||
else:
|
||||
raise FileNotFoundError('ERR_MAP_FILE: {}'.format(map_file))
|
||||
|
@ -69,7 +74,8 @@ class Map:
|
|||
line = int(self._line_nb)
|
||||
while line == 0:
|
||||
if self._data_list[line].find(maze_elmnt['robo']) != -1:
|
||||
self._init_position = (line, self._data_list[line].find(maze_elmnt['robo']))
|
||||
self._init_position = \
|
||||
(line, self._data_list[line].find(maze_elmnt['robo']))
|
||||
|
||||
# la position courante est la position initiale
|
||||
self._current_position = self._init_position
|
||||
|
@ -94,7 +100,6 @@ class Map:
|
|||
|
||||
# effectue le move et met a jour la carte
|
||||
|
||||
|
||||
def restore_backup(self, position):
|
||||
""" Charge une carte issue d'une sauvegarde """
|
||||
|
||||
|
|
|
@ -22,17 +22,17 @@ une sortie. Arrive sur ce point, la partie est terminee.
|
|||
|
||||
from map import Map
|
||||
import os
|
||||
import pickle
|
||||
# import pickle
|
||||
|
||||
# CONFIGURATION
|
||||
MAP_DIRECTORY = 'cartes/' # repertoire des fichiers carte
|
||||
MAP_EXTENTION = '.txt' # extention des fichiers carte
|
||||
MAP_DIRECTORY = 'cartes/' # repertoire des fichiers carte
|
||||
MAP_EXTENTION = '.txt' # extention des fichiers carte
|
||||
SAVED_GAME_FILENAME = '.backup' # fichier de sauvegarde
|
||||
DIRECTIONS = ['n', 'e', 's', 'o'] # commandes de deplacement
|
||||
MAZE_ELEMENTS = {'wall':'O', # elements disponibles dans le labyrinthe
|
||||
'door':'.',
|
||||
'exit':'U',
|
||||
'robo':'X'}
|
||||
MAZE_ELEMENTS = {'wall': 'O', # elements dispo dans le labyrinthe
|
||||
'door': '.',
|
||||
'exit': 'U',
|
||||
'robo': 'X'}
|
||||
# ERR_MAP_FILE = "ERR_MAP_FILE"
|
||||
ERR_PLAGE = "Il faut saisir un nombre dans la plage indiquée! "
|
||||
ERR_SAISIE = "Il faut saisir un nombre! "
|
||||
|
@ -43,8 +43,8 @@ MSG_SELECTED_MAP = "Vous avez fait le choix #{}, la carte «{}»."
|
|||
DEBUG = False
|
||||
|
||||
# VARIABLES
|
||||
maps_name_list = list() # liste des maps proposees a l'utilisateur
|
||||
selected_map = -1 # carte choisie par l'utilisateur
|
||||
maps_name_list = list() # liste des maps proposees a l'utilisateur
|
||||
user_select_map_id = -1 # carte choisie par l'utilisateur
|
||||
|
||||
|
||||
# FONCTIONS
|
||||
|
@ -65,7 +65,7 @@ else:
|
|||
if map_file[filename_len:] == MAP_EXTENTION:
|
||||
maps_name_list.append(map_file[:filename_len])
|
||||
|
||||
#Chercher si une sauvegarde existe
|
||||
# Chercher si une sauvegarde existe
|
||||
# TODO
|
||||
|
||||
# Affichage du debut de partie
|
||||
|
@ -77,27 +77,32 @@ for maps_name in maps_name_list:
|
|||
i += 1
|
||||
|
||||
# Choix de la carte par l'utilisateur
|
||||
while selected_map > len(maps_name_list) or selected_map < 0:
|
||||
selected_map = input(MSG_CHOOSE_MAP)
|
||||
while user_select_map_id > len(maps_name_list) or \
|
||||
user_select_map_id < 0:
|
||||
user_select_map_id = input(MSG_CHOOSE_MAP)
|
||||
try:
|
||||
selected_map = int(selected_map)
|
||||
user_select_map_id = int(user_select_map_id)
|
||||
except ValueError as except_detail:
|
||||
if DEBUG:
|
||||
print("ValueError: «{}»".format(except_detail))
|
||||
else:
|
||||
print(ERR_SAISIE)
|
||||
selected_map = -1
|
||||
user_select_map_id = -1
|
||||
continue
|
||||
|
||||
if selected_map > len(maps_name_list) or selected_map < 0:
|
||||
if user_select_map_id > len(maps_name_list) or \
|
||||
user_select_map_id < 0:
|
||||
print(ERR_PLAGE)
|
||||
|
||||
# DEBUT DE BOUCLE DE TOUR DE JEU
|
||||
# TODO : clear screen
|
||||
print(MSG_SELECTED_MAP.format(selected_map, maps_name_list[selected_map]))
|
||||
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[selected_map] + MAP_EXTENTION
|
||||
map_file = MAP_DIRECTORY + \
|
||||
maps_name_list[user_select_map_id] + \
|
||||
MAP_EXTENTION
|
||||
|
||||
# Affichage de la carte et de la position de jeu
|
||||
current_map = Map(map_file)
|
||||
|
|
Loading…
Reference in New Issue