diff --git a/dungeonbattle/display/display.py b/dungeonbattle/display/display.py index 45d2160..b64ac9c 100644 --- a/dungeonbattle/display/display.py +++ b/dungeonbattle/display/display.py @@ -1,5 +1,7 @@ import curses -from typing import Any +from typing import Any, Union + +from dungeonbattle.tests.screen import FakePad class Display: @@ -10,3 +12,9 @@ class Display: def refresh(self) -> None: raise NotImplementedError + + def newpad(self, height: int, width: int) -> Union[FakePad, Any]: + if self.screen: + return curses.newpad(height, width) + else: + return FakePad() diff --git a/dungeonbattle/display/mapdisplay.py b/dungeonbattle/display/mapdisplay.py index 56bc370..fd2cc89 100644 --- a/dungeonbattle/display/mapdisplay.py +++ b/dungeonbattle/display/mapdisplay.py @@ -16,7 +16,7 @@ class MapDisplay(Display): self.pack = pack self.map = m self.player = player - self.pad = curses.newpad(m.height, m.width + 1) + self.pad = self.newpad(m.height, m.width + 1) def update_pad(self) -> None: self.pad.addstr(0, 0, self.map.draw_string(self.pack)) diff --git a/dungeonbattle/display/menudisplay.py b/dungeonbattle/display/menudisplay.py index c46ba6b..d8252f8 100644 --- a/dungeonbattle/display/menudisplay.py +++ b/dungeonbattle/display/menudisplay.py @@ -18,12 +18,12 @@ class MenuDisplay(Display): self.toplefty = toplefty # Menu values are printed in pad - self.pad = curses.newpad(self.trueheight, self.truewidth + 1) + self.pad = self.newpad(self.trueheight, self.truewidth + 1) for i in range(self.trueheight): self.pad.addstr(i, 0, " " + self.values[i].value) # Menu box - self.menubox = curses.newpad(self.height, self.width) + self.menubox = self.newpad(self.height, self.width) self.menubox.addstr(0, 0, "┏" + "━" * (self.width - 2) + "┓") for i in range(1, self.height - 2): self.menubox.addstr(i, 0, "┃" + " " * (self.width - 2) + "┃") diff --git a/dungeonbattle/display/statsdisplay.py b/dungeonbattle/display/statsdisplay.py index 37d6f91..131d914 100644 --- a/dungeonbattle/display/statsdisplay.py +++ b/dungeonbattle/display/statsdisplay.py @@ -14,7 +14,7 @@ class StatsDisplay(Display): self.topleftx = topleftx self.toplefty = toplefty self.player = player - self.pad = curses.newpad(height, width) + self.pad = self.newpad(height, width) def update_pad(self) -> None: string = "" diff --git a/dungeonbattle/tests/screen.py b/dungeonbattle/tests/screen.py new file mode 100644 index 0000000..8963ce0 --- /dev/null +++ b/dungeonbattle/tests/screen.py @@ -0,0 +1,14 @@ +class FakePad: + """ + In order to run tests, we simulate a fake curses pad that accepts functions + but does nothing with them. + """ + def addstr(self, y: int, x: int, message: str) -> None: + pass + + def refresh(self, pminrow: int, pmincol: int, sminrow: int, + smincol: int, smaxrow: int, smaxcol: int) -> None: + pass + + def clear(self): + pass