From 1e7ca6026f1cd019ed0bffc8315d0eeafcf8b1c4 Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Fri, 16 Oct 2020 15:41:25 +0200 Subject: [PATCH] Tiles are now an enumeration --- dungeonbattle/interfaces.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index 1674427..3fa3422 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +from enum import Enum, auto + class Map: width: int @@ -22,28 +24,25 @@ class Map: lines = [line for line in lines if line] height = len(lines) width = len(lines[0]) - chars = [[Tile.from_char(c, x, y) + tiles = [[Tile.from_char(c) for x, c in enumerate(line)] for y, line in enumerate(lines)] - return Map(width, height, chars) + return Map(width, height, tiles) -class Tile: - x: int - y: int - char: str +class Tile(Enum): + EMPTY = auto() + WALL = auto() + FLOOR = auto() @staticmethod - def from_char(c: str, x: int, y: int): - t = Tile() - t.x = x - t.y = y - t.char = c - return c + def from_char(c: str): + return {'#': Tile.WALL, '.': Tile.FLOOR, ' ': Tile.EMPTY}[c] class Entity: - tile: Tile + x: int + y: int def move(self, x: int, y: int) -> None: - self.tile.x = x - self.tile.y = y + self.x = x + self.y = y