Boucle de jeu opérationnelle|TP_3.9

This commit is contained in:
Fred Z 2018-02-14 17:21:33 +01:00
parent 61a31dd0d6
commit 765c477315
3 changed files with 36 additions and 6 deletions

View File

@ -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

View File

@ -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:

View File

@ -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 """