Tiles are now an enumeration
This commit is contained in:
parent
d2f8a3b623
commit
182af96da0
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
from enum import Enum, auto
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Map:
|
class Map:
|
||||||
|
@ -24,18 +26,24 @@ class Map:
|
||||||
lines = [line for line in lines if line]
|
lines = [line for line in lines if line]
|
||||||
height = len(lines)
|
height = len(lines)
|
||||||
width = len(lines[0])
|
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:
|
class Entity:
|
||||||
y: int
|
|
||||||
x: int
|
x: int
|
||||||
img: str
|
y: int
|
||||||
|
|
||||||
def __init__(self, y: int, x: int, img: str):
|
|
||||||
self.y = y
|
|
||||||
self.x = x
|
|
||||||
self.img = img
|
|
||||||
|
|
||||||
def move(self, x: int, y: int) -> None:
|
def move(self, x: int, y: int) -> None:
|
||||||
self.x = x
|
self.x = x
|
||||||
|
|
Loading…
Reference in New Issue