From 881e6bbd13737bcdd759d5297a41983b7f608d37 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 15 Apr 2013 12:56:14 +0200 Subject: [PATCH] Tweak level object --- erdslangetjie/level.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/erdslangetjie/level.py b/erdslangetjie/level.py index a2c2a2d..3214cf6 100644 --- a/erdslangetjie/level.py +++ b/erdslangetjie/level.py @@ -7,6 +7,9 @@ class Level(object): def __init__(self): self.data = [] + self.exit_pos = [] + self.enter_pos = None + self.tiles = [] def load(self, levelfile): """Load the level""" @@ -14,9 +17,11 @@ class Level(object): 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): @@ -25,6 +30,17 @@ class Level(object): 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 -- 2.34.1