Places collectables items on the map
… but collectable are uncrossable as walls: BUG Begin to use a list of dicts to store all elements informations in the same place FIXME walk over collectables items FIXME generalise the use of the list of dicts
This commit is contained in:
parent
463e7864d7
commit
b24ca47faa
|
@ -41,12 +41,12 @@ guard without all the objects, he dies (according to the evolution theory).
|
|||
* [x] Initialize a Git repo on Github
|
||||
* [x] Create the labyrinth without the graphical user interface
|
||||
* [x] Start the graphical interface with PyGame
|
||||
* [ ] Represent the guard, _McGyver_ and the objects in your program
|
||||
* [x] Represent the guard, _McGyver_ and the objects in your program
|
||||
and placed them at the beginning of the game
|
||||
2. Animate the character
|
||||
* [ ] The only moving element is _McGyver_, create classes methods for
|
||||
animation and finding the exit
|
||||
* [ ] make a simplified version of the game in which _McGyver_ wins
|
||||
* [x] make a simplified version of the game in which _McGyver_ wins
|
||||
when he arrives in front of the goalkeeper
|
||||
3. Recovering objects
|
||||
* [ ] Add object management
|
||||
|
|
5
main.py
5
main.py
|
@ -24,7 +24,10 @@ MAZE_ELEMENTS_TILES = {
|
|||
'wall': 'img/transp-30.png',
|
||||
'exit': 'img/g-orange-transp-30.png',
|
||||
'plyr': 'img/player-30.png',
|
||||
'void': 'img/blue-white-30.png'
|
||||
'void': 'img/blue-white-30.png',
|
||||
'tube': 'img/1-blue-transp-30.png',
|
||||
'needle': 'img/2-blue-transp-30.png',
|
||||
'ether': 'img/3-blue-transp-30.png',
|
||||
}
|
||||
BACKGROUND_IMG = 'img/brick-800.png'
|
||||
UNKNOWN_TILE = 'img/unknown-30.png'
|
||||
|
|
21
map.py
21
map.py
|
@ -6,18 +6,33 @@ Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/
|
|||
This file is part of [_ocp3_ project](https://github.com/freezed/ocp3)
|
||||
"""
|
||||
import os
|
||||
import random
|
||||
|
||||
# CONFIGURATION
|
||||
|
||||
# Error message
|
||||
ERR_MAP = "ERR_MAP: «{}»"
|
||||
|
||||
ELEMENT_LIST = [
|
||||
{'symbol': 'n', 'name': 'needle', 'cross': True, 'ressurect': False, 'collect': True, 'tile': 'img/3-blue-transp-30.png'},
|
||||
{'symbol': 't', 'name': 'tube', 'cross': True, 'ressurect': False, 'collect': True, 'tile': 'img/1-blue-transp-30.png'},
|
||||
{'symbol': 'e', 'name': 'ether', 'cross': True, 'ressurect': False, 'collect': True, 'tile': 'img/2-blue-transp-30.png'},
|
||||
{'symbol': 'E', 'name': 'exit', 'cross': True, 'ressurect': False, 'collect': False, 'tile': 'd'},
|
||||
{'symbol': ' ', 'name': 'void', 'cross': True, 'ressurect': True, 'collect': False, 'tile': 'e'},
|
||||
{'symbol': '.', 'name': 'wall', 'cross': False, 'ressurect': False, 'collect': False, 'tile': 'f'},
|
||||
{'symbol': 'X', 'name': 'player', 'cross': False, 'ressurect': False, 'collect': False, 'tile': 'g'},
|
||||
{'symbol': '\n', 'name': 'nlin', 'cross': False, 'ressurect': False, 'collect': False, 'tile': 'h'},
|
||||
]
|
||||
|
||||
MAZE_SIZE = 15
|
||||
|
||||
MAZE_ELEMENTS = {'wall': '.',
|
||||
'exit': 'E',
|
||||
'plyr': 'X',
|
||||
'nlin': '\n',
|
||||
'needle': 'n',
|
||||
'tube': 't',
|
||||
'ether': 'e',
|
||||
'void': ' '}
|
||||
|
||||
# Issue possible d'un mouvement, garder le OK toujours en fin de liste
|
||||
|
@ -85,6 +100,12 @@ class Map:
|
|||
# Element under player at start
|
||||
self._element_under_player = MAZE_ELEMENTS['void']
|
||||
|
||||
# Place collectables on the map
|
||||
void_symbol = [element['symbol'] for element in ELEMENT_LIST if element['name'] == 'void'][0]
|
||||
collectables = (element['symbol'] for element in ELEMENT_LIST if element['collect'] == True)
|
||||
for symbol_to_place in collectables:
|
||||
position = random.choice([idx for (idx, value) in enumerate(self._map_in_a_string) if value == void_symbol])
|
||||
self.place_element(symbol_to_place, pos=position)
|
||||
|
||||
self.status = True
|
||||
self.status_message = MSG_START_GAME
|
||||
|
|
Loading…
Reference in New Issue