-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgameMap.py
158 lines (101 loc) · 3.66 KB
/
gameMap.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import database as d
import clock
#world map made up of ALL localities (for particular installation, or otherwise compartmentalize)
class World(object):
def __init__(self, width, height):
self.width = width
self.height = height
def getMap(self):
mWorldMap = [[None for y in range(self.height)] for x in range(self.width)]
#all localities share char T for now
for locality in d.getLocality():
x = locality.location[0]
y = locality.location[1]
mWorldMap[x][y] = "T"
return mWorldMap
def printMap(self):
print("The Known World")
mWorldMap = self.getMap()
mapHeight = len(mWorldMap[0])
y = 0
while (y < mapHeight):
rowAppearance = ""
for col in mWorldMap:
if (col[y] == None):
rowAppearance = rowAppearance + "."
else:
rowAppearance = rowAppearance + col[y]
print(rowAppearance)
y += 1
#town map made up of nodes
class Locality(object):
def __init__(self, model, location, width, height, name):
self.model = model
self.width = width
self.height = height
self.name = name
self.location = location
self.local_map = [[None for x in range(width)] for y in range(height)]
d.addLocality(self)
def getName(self):
return self.name
def getWidth(self):
return self.width
def getMap(self):
return self.local_map
def claim_node(self, xy, entity):
claimed = False
x = xy[0]
y = xy[1]
if self.local_map[x][y] is None:
self.local_map[x][y] = entity
claimed = True
return claimed
def check_node(self, node):
is_empty = False
if node is None:
is_empty = True
return is_empty
#algorithm checks indices reflected around the diagonal, starting from upper left
#I feel like this algorithm is confusing, but it's the best I can do right now
def find_property(self):
xy = None
for i in range(len(self.local_map)):
j = 0
if xy is not None:
break
while i >= j:
if self.check_node(self.local_map[i][j]):
xy = (i,j)
break
if self.check_node(self.local_map[j][i]):
xy = (j,i)
break
j += 1
return xy
def printMap(self):
print(self.name)
mLocalMap = self.getMap()
for row in mLocalMap:
rowAppearance = ""
for i in row:
if (i == None):
rowAppearance = rowAppearance + "."
else:
rowAppearance = rowAppearance + i.character
print(rowAppearance)
def get_print_map(self):
print_map = ""
for row in self.local_map:
rowAppearance = ""
for i in row:
if (i == None):
rowAppearance = rowAppearance + "X"
else:
rowAppearance = rowAppearance + i.character
print_map += rowAppearance + "\n"
return print_map
def getDayNum(self):
return self.model.getDayNum()
def date(self):
return self.model.calendar.date()