From 2e82849395833d950f1c62e8a50397c02c361ed6 Mon Sep 17 00:00:00 2001 From: Charles Peyrat Date: Sun, 11 Oct 2020 15:24:51 +0200 Subject: [PATCH] Sanitizing data structure --- dungeonbattle/interfaces.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index 838cbec..2cef098 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -22,31 +22,22 @@ class Map: lines = [line for line in lines if line] height = len(lines) width = len(lines[0]) - chars = [[Tile.from_char(c, x, y) - for x, c in enumerate(line)] for y, line in enumerate(lines)] - return Map(width, height, chars) + return Map(width, height, lines) def draw_string(self) -> str: return "\n".join("".join(tile.char for tile in line) for line in self.tiles) -class Tile: - x: int - y: int - char: str - - @staticmethod - def from_char(c: str, x: int, y: int): - t = Tile() - t.x = x - t.y = y - t.char = c - return c - - class Entity: - tile: Tile + y: int + x: int + img: str + + def __init__(self, y: int, x: int, img: str): + self.y = y + self.x = x + self.img = img def move(self, x: int, y: int) -> None: - self.tile.x = x - self.tile.y = y + self.x = x + self.y = y