def __init__(self):
self.data = []
+ self.exit_pos = []
+ self.enter_pos = None
+ self.tiles = []
def load(self, levelfile):
"""Load the level"""
for line in levelfile.readlines():
self.data.append(list(line))
- def get_tiles(self):
- """Return a list of tiles for the level"""
- tiles = []
+ def load_tiles(self):
+ """Load the list of tiles for the level"""
+ self.tiles = []
+ self.exit_pos = []
+ self.enter_pos = None
for j, line in enumerate(self.data):
tile_line = []
for i, c in enumerate(line):
elif c == '.':
tile_line.append(load_image('tiles/wall.bmp'))
elif c == 'E' or c == 'X':
+ if c == 'E':
+ if self.enter_pos:
+ raise RuntimeError('Multiple entry points')
+ self.enter_pos = (i, j)
+ else:
+ self.exit_pos.append((i, j))
tile_line.append(load_image('tiles/door.bmp'))
- tiles.append(tile_line)
- return tiles
+ self.tiles.append(tile_line)
+
+ def get_tiles(self):
+ return self.tiles
+
+ def at_exit(self, pos):
+ return pos in self.exit_pos