DONE05 refermer la porte «derriere»|TP_3.9|ROBOC

TODO13 UnboundLocalError: local variable 'direction' referenced before assignment
This commit is contained in:
Fred Z 2018-02-15 11:00:12 +01:00
parent 3500192083
commit 2407ceaafb
2 changed files with 15 additions and 8 deletions

View File

@ -21,7 +21,7 @@ MAZE_ELEMENTS = {'wall': 'O', # elements dispo dans le labyrinthe
'door': '.',
'exit': 'U',
'robo': 'X',
'trace': ' '}
'void': ' '}
# Issue possible d'un mouvement, garder le OK toujours en fin de liste
MOVE_STATUS = ['bad', 'wall', 'exit', 'door', 'ok']

View File

@ -97,6 +97,9 @@ class Map:
MAZE_ELEMENTS['robo']
)
# Element sous le robo
self._element_under_robo = MAZE_ELEMENTS['void']
# Quelques controle sur la carte:
# dimensions assez grande pour deplacer un robo?
if self._column_nb < MIN_MAP_SIDE or \
@ -153,10 +156,18 @@ class Map:
steps = 0
# direction non conforme
# TODO13 UnboundLocalError: local variable 'direction' referenced before assignment
if direction not in DIRECTIONS:
move_status = 0
else:
# supprime le robo de son emplacement actuel
self._data_text = self._data_text.replace(
MAZE_ELEMENTS['robo'],
self._element_under_robo
)
# pour chaque pas on recupere la position suivante
while steps < goal:
steps += 1
@ -175,6 +186,8 @@ class Map:
else: # juste au cas ou
raise NotImplementedError(ERR_UNKNOW)
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
next_char = self._data_text[next_position]
@ -189,20 +202,14 @@ class Map:
elif next_char == MAZE_ELEMENTS['door']:
self._robo_position = next_position
self._element_under_robo = MAZE_ELEMENTS['door']
move_status = 3
steps = goal
# TODO05 replacer la porte ensuite
else:
self._robo_position = next_position
move_status = 4
# supprime le robo de son emplacement precedent
self._data_text = self._data_text.replace(
MAZE_ELEMENTS['robo'],
MAZE_ELEMENTS['trace']
)
# place le robo sur sa nouvelle position
self.place_element(MAZE_ELEMENTS['robo'])