-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
52 lines (37 loc) · 1.25 KB
/
game.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
#python3
import numpy as np
class Map_thing:
def __init__(self, t_char, mohs):
self.t_char = t_char
self.mohs = mohs
def print_self(self):
return self.t_char
def get_mohs(self):
return self.mohs
class Map:
def __init__(self, width, height, density ):
self.width = width
self.height = height
self.density = density
self._wall = Map_thing('',10)
self._space = Map_thing(' ',0)
self._map = []
def _init_map(self, density=None):
den = density if density is not None else self.density
for col in range(self.width):
if col == 0 or col == self.width - 1:
self._map.append([self._wall] * self.height)
else:
column = [self._wall]
column.append([self._wall if np.random.randint(100) <= den else self._space for i in range(self.height - 2)])
column.append(self._wall)
self._map.append(column)
def _print(self):
map_str = ''
for i in range(self.width):
for j in range(self.height):
map_str += self._map[i][j].t_char
return map_str
if __name__ == "__main__":
m = Map(10, 10, 50)
print(m._print())