Get a tile from its representation
This commit is contained in:
parent
eb1e125d4e
commit
1054d8e57a
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
from enum import Enum, auto
|
||||
from enum import Enum
|
||||
|
||||
|
||||
|
||||
|
@ -31,17 +31,21 @@ class Map:
|
|||
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)
|
||||
return "\n".join("".join(tile.value for tile in line)
|
||||
for line in self.tiles)
|
||||
|
||||
|
||||
class Tile(Enum):
|
||||
EMPTY = auto()
|
||||
WALL = auto()
|
||||
FLOOR = auto()
|
||||
EMPTY = ' '
|
||||
WALL = '#'
|
||||
FLOOR = '.'
|
||||
|
||||
@staticmethod
|
||||
def from_char(c: str):
|
||||
return {'#': Tile.WALL, '.': Tile.FLOOR, ' ': Tile.EMPTY}[c]
|
||||
for t in Tile:
|
||||
if t.value == c:
|
||||
return t
|
||||
raise ValueError(f"Tile not found : {c}")
|
||||
|
||||
|
||||
class Entity:
|
||||
|
|
|
@ -5,7 +5,7 @@ from dungeonbattle.interfaces import Map
|
|||
|
||||
class TestInterfaces(unittest.TestCase):
|
||||
def test_map(self) -> None:
|
||||
m = Map.load_from_string("ab\ncd\n")
|
||||
m = Map.load_from_string(".#\n#.\n")
|
||||
self.assertEqual(m.width, 2)
|
||||
self.assertEqual(m.height, 2)
|
||||
self.assertEqual(m.draw_string(), "ab\ncd")
|
||||
self.assertEqual(m.draw_string(), ".#\n#.")
|
||||
|
|
Loading…
Reference in New Issue