DONE03, DONE04 & TODO11|TP_3.9|ROBOC
- DONE03: suppression de __getattr__ (inutile & conflit avec pickle) - DONE08: ajout de la commande `quitter et sauvegarder` - TODO11: affiche la liste des commandes
This commit is contained in:
parent
442d2b2bff
commit
71043085fc
|
@ -12,8 +12,10 @@ Ce fichier fait partie du projet `roboc`
|
|||
|
||||
MAP_DIRECTORY = 'cartes/' # repertoire des fichiers carte
|
||||
MAP_EXTENTION = '.txt' # extention des fichiers carte
|
||||
SAVED_GAME_FILENAME = '.backup' # fichier de sauvegarde
|
||||
BACKUP_FILE = '.backup' # fichier de sauvegarde
|
||||
DIRECTIONS = ['N', 'S', 'E', 'O'] # commandes de deplacement
|
||||
COMMANDS = {'quit': 'Q', # commandes d'interuption
|
||||
'help': 'H'}
|
||||
MAZE_ELEMENTS = {'wall': 'O', # elements dispo dans le labyrinthe
|
||||
'door': '.',
|
||||
'exit': 'U',
|
||||
|
@ -32,6 +34,7 @@ ERR_UNKNOW = ERR_ + "personne n'est censé arriver ici…"
|
|||
|
||||
MIN_MAP_SIDE = 3
|
||||
MSG_DISCLAMER = "Bienvenue dans Roboc."
|
||||
MSG_BACKUP = "Partie sauvegardée."
|
||||
MSG_AVAIBLE_MAP = "Cartes disponible: "
|
||||
MSG_CHOOSE_MAP = "Choississez un numéro de carte: "
|
||||
MSG_CHOOSE_MOVE = "Votre deplacement: "
|
||||
|
|
|
@ -127,14 +127,6 @@ class Map:
|
|||
self.status = False
|
||||
self.status_message = ERR_MAP_FILE.format(map_file)
|
||||
|
||||
# TODO03 est-ce utile de conserver cette methode?
|
||||
def __getattr__(self, name):
|
||||
"""
|
||||
Si un attribut manque a l'appel (_robo_position ou
|
||||
_init_robo_position)
|
||||
"""
|
||||
return None
|
||||
|
||||
def map_print(self):
|
||||
""" Affiche la carte avec la position de jeu courante """
|
||||
print(self._data_text)
|
||||
|
|
|
@ -17,9 +17,9 @@ Source: https://openclassrooms.com/courses/apprenez-a-programmer-en-python/exerc
|
|||
"""
|
||||
|
||||
import os
|
||||
import pickle
|
||||
from map import Map
|
||||
from configuration import *
|
||||
# import pickle
|
||||
|
||||
# DEBUT DU JEU
|
||||
|
||||
|
@ -85,32 +85,41 @@ while current_map.status:
|
|||
|
||||
# choix du deplacement
|
||||
user_select_move = input(MSG_CHOOSE_MOVE).upper()
|
||||
|
||||
# TODO08 quitter et sauvegarder
|
||||
|
||||
# traitement du deplacement
|
||||
move_status_id = current_map.move_to(user_select_move)
|
||||
cls() # clear screen
|
||||
|
||||
# TODO09 ranger les status dans un dict('ok': MSG_OK, …)
|
||||
if MOVE_STATUS[move_status_id] == 'ok':
|
||||
print('MSG_OK')
|
||||
if user_select_move == COMMANDS['quit']: # quitter et sauvegarder
|
||||
with open(BACKUP_FILE, 'wb') as backup_file:
|
||||
pickle.Pickler(backup_file).dump(current_map)
|
||||
|
||||
elif MOVE_STATUS[move_status_id] == 'bad':
|
||||
print('MSG_BAD')
|
||||
# TODO12 afficher un recap des commandes dispo
|
||||
# elif user_select_move == COMMANDS['help']: # Affiche les commandes
|
||||
# print(COMMANDS, DIRECTIONS)
|
||||
|
||||
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
|
||||
current_map.status_message = MSG_BACKUP
|
||||
|
||||
else: # juste au cas ou…
|
||||
raise NotImplementedError(ERR_UNKNOW)
|
||||
else: # traitement du deplacement
|
||||
move_status_id = current_map.move_to(user_select_move)
|
||||
|
||||
# TODO09 ranger les status dans un dict('ok': MSG_OK, …)
|
||||
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…
|
||||
raise NotImplementedError(ERR_UNKNOW)
|
||||
|
||||
# TODO10 rester dans la boucle si la carte n'est pas conforme
|
||||
if current_map.status is False:
|
||||
|
|
Loading…
Reference in New Issue