From b12764b355996cc83cec0db73817675183f080aa 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 1674427..838cbec 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -26,6 +26,9 @@ class Map: for x, c in enumerate(line)] for y, line in enumerate(lines)] return Map(width, height, chars) + def draw_string(self) -> str: + return "\n".join("".join(tile.char for tile in line) for line in self.tiles) + class Tile: x: int 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")