From a0530b67fb22a57bef3b7c60648db0be062e64d6 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 16 Oct 2020 14:00:38 +0200 Subject: [PATCH] Draw a map in a string to make the render in the screen easier --- dungeonbattle/interfaces.py | 3 +++ dungeonbattle/interfaces_test.py | 1 + 2 files changed, 4 insertions(+) diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index 3fa3422..537b256 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -28,6 +28,9 @@ class Map: for x, c in enumerate(line)] for y, line in enumerate(lines)] return Map(width, height, tiles) + def draw_string(self) -> str: + return "\n".join("".join(tile.char for tile in line) for line in self.tiles) + class Tile(Enum): EMPTY = auto() diff --git a/dungeonbattle/interfaces_test.py b/dungeonbattle/interfaces_test.py index a987b37..479a9ac 100644 --- a/dungeonbattle/interfaces_test.py +++ b/dungeonbattle/interfaces_test.py @@ -8,3 +8,4 @@ class TestInterfaces(unittest.TestCase): m = Map.load_from_string("ab\ncd\n") self.assertEqual(m.width, 2) self.assertEqual(m.height, 2) + self.assertEqual(m.draw_string(), "ab\ncd")