-
Notifications
You must be signed in to change notification settings - Fork 0
/
building.py
197 lines (163 loc) · 7.3 KB
/
building.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from colorama import Back, Style
import time
class Building:
buildingList = []
def __init__(self,x,y):
self.coordinates = [x,y]
self.health = 10
self.death = False
Building.buildingList.append(self)
class Hut(Building):
hutsList = []
def __init__(self,x,y):
super().__init__(x,y)
def render(self,colorArray):
if(self.health <=0):
self.color = Back.LIGHTBLACK_EX + " " + Style.RESET_ALL
self.death = True
elif(self.health > 5):
self.color = Back.LIGHTYELLOW_EX + " " + Style.RESET_ALL
elif(self.health > 3):
self.color = Back.LIGHTRED_EX + " " + Style.RESET_ALL
else:
self.color = Back.YELLOW + " " + Style.RESET_ALL
colorArray[self.coordinates[0]][self.coordinates[1]] = self.color
return colorArray
def idUpdate(self,idArray):
idArray[self.coordinates[0]][self.coordinates[1]] = 2
return idArray
class Canon(Building):
canonsList = []
def __init__(self,xCoordinate,yCoordinate):
##self.coordinates = [xCoordinate,yCoordinate]
##self.health = 10
super().__init__(xCoordinate,yCoordinate)
self.occupied = False
self.victim = None
self.target = None
self.init = time.time()
##self.death = False
def render(self,colorArray,):
## canons
if(self.health>7):
self.color = Back.BLACK +" "+ Style.RESET_ALL
elif(self.health > 5):
self.color = Back.LIGHTBLACK_EX +" " + Style.RESET_ALL
elif(self.health > 3):
self.color = Back.RED + " " + Style.RESET_ALL
else:
self.color = Back.LIGHTGREEN_EX + " " + Style.RESET_ALL
self.death = True
colorArray[self.coordinates[0]][self.coordinates[1]] = self.color
return colorArray
def idUpdate(self, idArray):
if(self.death==False):
idArray[self.coordinates[0]][self.coordinates[1]] = 3
return idArray
def shoot(self,king,Barbarians):
if(self.death==False):
min_distance = 10
print(self.occupied)
self.target = None
if(self.victim!=None):
if(abs(self.victim.coordinates[0]-self.coordinates[0])<5 and abs(self.victim.coordinates[1]-self.coordinates[1])<5):
print('yess')
else:
print('nooo')
self.victim = None
self.occupied = False
if(abs(king.coordinates[0]-self.coordinates[0])<5 and abs(king.coordinates[1]-self.coordinates[1])<5 and king.death == False):
distance = abs(king.coordinates[0]-self.coordinates[0]) + abs(king.coordinates[1]-self.coordinates[1])
if(distance<min_distance):
min_distance = distance
self.target = king
for barbarian in Barbarians.barbariansList:
if(abs(barbarian.coordinates[0]-self.coordinates[0])<5 and abs(barbarian.coordinates[1]-self.coordinates[1])<5):
distance = abs(barbarian.coordinates[0]-self.coordinates[0]) + abs(barbarian.coordinates[1]-self.coordinates[1])
if(barbarian.death == False):
if(distance<min_distance):
min_distance = distance
self.target = barbarian
print(self.target)
if(self.target!=None):
if(self.occupied==False):
self.victim = self.target
self.occupied = True
if(min_distance<10):
self.victim.health -= 1
self.occupied = True
if(self.victim.health <=0):
self.victim = None
self.occupied = False
else:
print(self.coordinates, self.victim.coordinates)
print(abs(self.victim.coordinates[0]-self.coordinates[0])<5 and abs(self.victim.coordinates[0]-self.coordinates[0])<5)
if(self.target != self.victim):
if(abs(self.victim.coordinates[0]-self.coordinates[0])<5 and abs(self.victim.coordinates[1]-self.coordinates[1])<5):
print('yes')
else:
self.victim = self.target
print(self.victim)
if(time.time()-self.init > 1):
self.init = time.time()
self.victim.health -= 1
if(self.victim.health <=0):
self.victim = None
self.occupied = False
class Wall(Building):
wallsList = []
def __init__(self, x, y):
super().__init__(x,y)
def render(self, colorArray):
if(self.health <= 0):
self.color = Back.LIGHTGREEN_EX + " " + Style.RESET_ALL
else:
self.color = Back.LIGHTBLACK_EX + " " + Style.RESET_ALL
colorArray[self.coordinates[0]][self.coordinates[1]] = self.color
return colorArray
def idUpdate(self, idArray):
if(self.health>0):
idArray[self.coordinates[0]][self.coordinates[1]] = 7
return idArray
class Townhall(Building):
def __init__(self):
self.rows = 4
self.columns = 3
self.health = 10
self.death = False
def render(self,colorArray,idArray):
if(self.health>0):
for i in range(self.rows):
for j in range(self.columns):
colorArray[int(40/2)-1+i][int(80/2)-1+j]= Back.YELLOW + " " + Style.RESET_ALL
elif(self.health > 5):
for i in range(self.rows):
for j in range(self.columns):
colorArray[int(40/2)-1+i][int(80/2)-1+j]= Back.LIGHTYELLOW_EX + " " + Style.RESET_ALL
elif(self.health > 3):
for i in range(self.rows):
for j in range(self.columns):
colorArray[int(40/2)-1+i][int(80/2)-1+j]= Back.LIGHTRED_EX + " " + Style.RESET_ALL
else:
self.death = True
for i in range(self.rows):
for j in range(self.columns):
colorArray[int(40/2)-1+i][int(80/2)-1+j]= Back.LIGHTBLACK_EX + " " + Style.RESET_ALL
""" for i in (18,22):
for j in range(6):
colorArray[i][int(80/2)-2+j] = Back.LIGHTBLACK_EX + str(idArray[i][int(80/2)-2+j]) + Style.RESET_ALL
for i in range(3):
for j in (38,43):
colorArray[int(40/2)-1+i][j]= Back.LIGHTBLACK_EX + str(idArray[int(40/2)-1+i][j]) + Style.RESET_ALL """
return colorArray
def idUpdate(self, idArray):
for i in range(self.rows):
for j in range(self.columns):
idArray[int(40/2)-1+i][int(80/2)-1+j] = 4
""" for i in (18,22):
for j in range(6):
idArray[i][int(80/2)-2+j] = 6
for i in range(3):
for j in (38,43):
idArray[int(40/2)-1+i][j]= 6 """
return idArray