blob: a365b89e14b636605f2af4c4898e94a91c5996eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
from Vec import Vec2
class Walls:
"""Contains the walls of a game.
Supports iterating over the walls and checking if there is a wall at a specific coordinate.
Useful as a wrapper to later increase performance of these operations."""
def __init__(self, walls: list[Vec2]) -> None:
self._walls = walls
@staticmethod
def fromString(wallString: str) -> 'Walls':
walls = []
y = 0
for line in wallString.split('\n'):
x = 0
for char in line:
if char == "#":
walls.append(Vec2(x, y))
x += 1
y += 1
return Walls(walls)
@staticmethod
def empty() -> 'Walls':
return Walls([])
def walls(self) -> list[Vec2]:
return self._walls
def wallAt(self, pos: Vec2) -> bool:
return (pos in self._walls)
def width(self) -> int:
return max(self._walls, key=lambda p: p.x).x + 1
def height(self) -> int:
return max(self._walls, key=lambda p: p.y).y + 1
|