From: Neil Date: Mon, 15 Apr 2013 10:56:14 +0000 (+0200) Subject: Tweak level object X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=881e6bbd13737bcdd759d5297a41983b7f608d37;p=erdslangetjie.git Tweak level object --- 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