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