Tiles are now an enumeration

This commit is contained in:
Nicolas Margulies 2020-10-16 15:41:25 +02:00
parent d2f8a3b623
commit 182af96da0
1 changed files with 16 additions and 8 deletions

View File

@ -1,4 +1,6 @@
#!/usr/bin/env python
from enum import Enum, auto
class Map:
@ -24,18 +26,24 @@ class Map:
lines = [line for line in lines if line]
height = len(lines)
width = len(lines[0])
return Map(width, height, lines, [])
tiles = [[Tile.from_char(c)
for x, c in enumerate(line)] for y, line in enumerate(lines)]
return Map(width, height, tiles)
class Tile(Enum):
EMPTY = auto()
WALL = auto()
FLOOR = auto()
@staticmethod
def from_char(c: str):
return {'#': Tile.WALL, '.': Tile.FLOOR, ' ': Tile.EMPTY}[c]
class Entity:
y: int
x: int
img: str
def __init__(self, y: int, x: int, img: str):
self.y = y
self.x = x
self.img = img
y: int
def move(self, x: int, y: int) -> None:
self.x = x