-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.py
51 lines (42 loc) · 1.66 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from random import randint
from tile import Tile, plains, forest, pines, mountain, water
class Map:
def __init__(self, width: int, height: int) -> None:
self.width = width
self.height = height
self.map_data: list[list[Tile]]
self.generate_map()
self.generate_patch(forest, 2, 5, 7)
self.generate_patch(pines, 2, 2, 5)
self.generate_patch(mountain, 3, 5, 7)
self.generate_patch(water, 1, 10, 12)
def generate_map(self) -> None:
self.map_data = [[plains for _ in range(self.width)] for _ in range(self.height)]
def generate_patch(
self,
tile: Tile,
num_patches: int,
min_size: int,
max_size: int,
irregular: bool = True
) -> None:
for _ in range(num_patches):
width = randint(min_size, max_size)
height = randint(min_size, max_size)
start_x = randint(1, self.width - width - 1)
start_y = randint(1, self.height - height - 1)
if irregular:
init_start_x = randint(3, self.width - max_size)
for i in range(height):
if irregular:
width = randint(int(0.7 * max_size), max_size)
start_x = init_start_x - randint(1, 2)
for j in range(width):
self.map_data[start_y + i][start_x + j] = tile
def display_map(self) -> None:
frame = "x" + self.width * "=" + "x"
print(frame)
for row in self.map_data:
row_tiles = [tile.symbol for tile in row]
print("|" + "".join(row_tiles) + "|")
print(frame)