-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.py
30 lines (21 loc) · 780 Bytes
/
map.py
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
class Map:
map_array: list[list[str]]
points: list[tuple[int, int]]
def __init__(self, h: int, w: int, map_array=[]):
self.map = map_array
self.w = w
self.h = h
self.points = []
def check_out_of_bounds(self, y: int, x: int) -> bool:
return x >= self.w or x < 0 or y >= self.h or y < 0
# Obstacles
def is_block(self, y: int, x: int):
return self.map[y][x].lower() == 'x'
def set_points(self, points):
self.points = points
def get_item(self, y, x) -> str:
return self.map[y][x]
def append_row(self, row: list[str]) -> None:
if len(row) != self.w:
raise ValueError('Invalid size of columns in this row:\n', str(row))
self.map.append(row)