-
Notifications
You must be signed in to change notification settings - Fork 4
/
bomb.py
274 lines (227 loc) · 11 KB
/
bomb.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
''' The Bomb Class
The bomb class does not inherit
any other class, it creates a bomb,
keeps count of bombs and their positions,
explosion, and then clears that explosion.
'''
from check import checkboard
from board import Board
from enemy import Enemy
from manage import Manage
# An instance of manage to keep
# count of time, score and lives.
MANAGEINSTANCE = Manage()
class Bomb:
'''Bomb class has all bomb functions.'''
# Arrays for x,y coordinates of Bombs
Bomba = []
Bombb = []
# the explosion function to explode bombs.
# Dealt individually for 4 positions around a coordinate.
def explosion(self, alpha, beta):
'''Deals with explosion of bomb'''
# For the oroginal position.
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
beta = beta - 1
# For down.
if checkboard(self, alpha, beta) == 'enemy':
MANAGEINSTANCE.changescore('enemy')
Enemy.removeenemy(self, alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'empty':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomberman':
MANAGEINSTANCE.changelives()
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomb':
self.removebomb(alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'brick':
MANAGEINSTANCE.changescore('brick')
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
alpha = alpha + 1
beta = beta + 1
# For Right
if checkboard(self, alpha, beta) == 'enemy':
MANAGEINSTANCE.changescore('enemy')
Enemy.removeenemy(self, alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'empty':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomberman':
MANAGEINSTANCE.changelives()
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomb':
self.removebomb(alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'brick':
MANAGEINSTANCE.changescore('brick')
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
alpha = alpha - 2
# For Left
if checkboard(self, alpha, beta) == 'enemy':
MANAGEINSTANCE.changescore('enemy')
Enemy.removeenemy(self, alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'empty':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomberman':
MANAGEINSTANCE.changelives()
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomb':
self.removebomb(alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'brick':
MANAGEINSTANCE.changescore('brick')
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
alpha = alpha + 1
beta = beta + 1
# For Down
if checkboard(self, alpha, beta) == 'enemy':
MANAGEINSTANCE.changescore('enemy')
Enemy.removeenemy(self, alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'empty':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomberman':
MANAGEINSTANCE.changelives()
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'bomb':
self.removebomb(alpha, beta)
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
if checkboard(self, alpha, beta) == 'brick':
MANAGEINSTANCE.changescore('brick')
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = 'e'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = 'e'
beta = beta - 1
# Function to clear explosion after an
# explosion has lasted for 10 frames.
def clearexplosion(self, alpha, beta):
'''clears bomb explosion'''
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' '
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' '
beta = beta - 1
if checkboard(self, alpha, beta) == 'explosion':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' '
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' '
alpha = alpha + 1
beta = beta + 1
if checkboard(self, alpha, beta) == 'explosion':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' '
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' '
alpha = alpha - 2
if checkboard(self, alpha, beta) == 'explosion':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' '
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' '
alpha = alpha + 1
beta = beta + 1
if checkboard(self, alpha, beta) == 'explosion':
for j in range(0, 4):
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + j] = ' '
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + j] = ' '
beta = beta - 1
self.removebomb(alpha, beta)
# Once an explosion has been cleared
# The removebomb function removes those
# bomb coordinates from the bomb array.
def removebomb(self, alpha, beta):
'''removes bomb from bomb array'''
i = 0
while i < len(self.Bomba):
j = 0
if self.Bomba[i] == alpha:
while j < len(self.Bombb):
if self.Bombb[j] == beta:
del self.Bomba[i]
del self.Bombb[j]
j += 1
i += 1
# The bombcounter funciton displays
# Seconds to explosion at bomb coordinates.
def bombcounter(self):
'''keeps a count of number of bombs'''
i = 0
while i < len(Bomb.Bomba):
if Board.board[(Bomb.Bombb[i] + 1) * 2 +
1][(Bomb.Bomba[i] + 1) * 4 + 2] == '2':
Board.board[(Bomb.Bombb[i] + 1) * 2 +
1][(Bomb.Bomba[i] + 1) * 4 + 2] = '1'
Board.board[(Bomb.Bombb[i] + 1) * 2 +
1][(Bomb.Bomba[i] + 1) * 4 + 1] = '1'
Board.board[(Bomb.Bombb[i] + 1) *
2][(Bomb.Bomba[i] + 1) * 4 + 2] = '1'
Board.board[(Bomb.Bombb[i] + 1) *
2][(Bomb.Bomba[i] + 1) * 4 + 1] = '1'
elif Board.board[(Bomb.Bombb[i] + 1) * 2 + 1][(Bomb.Bomba[i] + 1) * 4 + 2] == '1':
Board.board[(Bomb.Bombb[i] + 1) * 2 +
1][(Bomb.Bomba[i] + 1) * 4 + 2] = '0'
Board.board[(Bomb.Bombb[i] + 1) * 2 +
1][(Bomb.Bomba[i] + 1) * 4 + 1] = '0'
Board.board[(Bomb.Bombb[i] + 1) *
2][(Bomb.Bomba[i] + 1) * 4 + 2] = '0'
Board.board[(Bomb.Bombb[i] + 1) *
2][(Bomb.Bomba[i] + 1) * 4 + 1] = '0'
elif Board.board[(Bomb.Bombb[i] + 1) * 2 + 1][(Bomb.Bomba[i] + 1) * 4 + 2] == '0':
Bomb.explosion(self, Bomb.Bomba[i], Bomb.Bombb[i])
elif Board.board[(Bomb.Bombb[i] + 1) * 2 + 1][(Bomb.Bomba[i] + 1) * 4 + 2] == 'e':
Bomb.clearexplosion(
self, Bomb.Bomba[i], Bomb.Bombb[i])
i += 1
# Function to generate bombs.
def generatebomb(self, alpha, beta):
'''generates bombs'''
Bomb.Bomba.append(alpha)
Bomb.Bombb.append(beta)
Board.board[(beta + 1) * 2][(alpha + 1) * 4] = '['
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + 1] = '2'
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + 2] = '2'
Board.board[(beta + 1) * 2][(alpha + 1) * 4 + 3] = ']'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4] = '['
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + 1] = '2'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + 2] = '2'
Board.board[(beta + 1) * 2 + 1][(alpha + 1) * 4 + 3] = ']'