Tiles are now an enumeration
This commit is contained in:
parent
c8de541eee
commit
1e7ca6026f
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
from enum import Enum, auto
|
||||||
|
|
||||||
|
|
||||||
class Map:
|
class Map:
|
||||||
width: int
|
width: int
|
||||||
|
@ -22,28 +24,25 @@ 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])
|
||||||
chars = [[Tile.from_char(c, x, y)
|
tiles = [[Tile.from_char(c)
|
||||||
for x, c in enumerate(line)] for y, line in enumerate(lines)]
|
for x, c in enumerate(line)] for y, line in enumerate(lines)]
|
||||||
return Map(width, height, chars)
|
return Map(width, height, tiles)
|
||||||
|
|
||||||
|
|
||||||
class Tile:
|
class Tile(Enum):
|
||||||
x: int
|
EMPTY = auto()
|
||||||
y: int
|
WALL = auto()
|
||||||
char: str
|
FLOOR = auto()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_char(c: str, x: int, y: int):
|
def from_char(c: str):
|
||||||
t = Tile()
|
return {'#': Tile.WALL, '.': Tile.FLOOR, ' ': Tile.EMPTY}[c]
|
||||||
t.x = x
|
|
||||||
t.y = y
|
|
||||||
t.char = c
|
|
||||||
return c
|
|
||||||
|
|
||||||
|
|
||||||
class Entity:
|
class Entity:
|
||||||
tile: Tile
|
x: int
|
||||||
|
y: int
|
||||||
|
|
||||||
def move(self, x: int, y: int) -> None:
|
def move(self, x: int, y: int) -> None:
|
||||||
self.tile.x = x
|
self.x = x
|
||||||
self.tile.y = y
|
self.y = y
|
||||||
|
|
Loading…
Reference in New Issue