-
Notifications
You must be signed in to change notification settings - Fork 0
/
bomb.py
83 lines (75 loc) · 3.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
import time
import copy
from board import Matrix
class Bomb(object):
def __init__(self, bombcord, explode_locations,
score, enemy_cord, enemy2_cord):
self.created_time = time.time()
self.curr_tick = 0
def bomb_view(self, bombcord, n):
for i in range(2):
for j in range(1, 3):
Matrix[bombcord[0] + i][bombcord[1] + j] = n
Matrix[bombcord[0]][bombcord[1]] = "["
Matrix[bombcord[0]][bombcord[1] + 3] = "]"
Matrix[bombcord[0] + 1][bombcord[1]] = "["
Matrix[bombcord[0] + 1][bombcord[1] + 3] = "]"
def update(self, bombcord, explode_locations,
score, enemy_cord, enemy2_cord): # Upadates the state of bomb
self.curr_tick = int(time.time() - self.created_time)
if self.curr_tick >= 3:
self.explode(bombcord, explode_locations,
score, enemy_cord, enemy2_cord)
else:
self.curr_tick += 1
if self.curr_tick == 1:
self.bomb_view(bombcord, 1)
elif self.curr_tick == 2:
self.bomb_view(bombcord, 0)
def affected_area(self, x, y, score, explode_locations,
enemy_cord, enemy2_cord):
if Matrix[x][y] != 'X':
if Matrix[x][y] == '/':
score[0] += 20
elif Matrix[x][y] == 'E':
score[0] += 100
for p in enemy_cord:
kun = copy.deepcopy(p)
if [x, y] in kun:
enemy_cord.remove(p)
elif Matrix[x][y] == 'F':
score[0] += 130
for p in enemy2_cord:
kun = copy.deepcopy(p)
if [x, y] in kun:
enemy2_cord.remove(p)
for i in range(2):
for j in range(4):
explode_locations.append([x + i, y + j])
return
else:
return
def explode(self, bombcord, explode_locations,
score, enemy_cord, enemy2_cord):
self.affected_area(bombcord[0] - 2, bombcord[1],
score, explode_locations, enemy_cord, enemy2_cord)
self.affected_area(bombcord[0] + 2, bombcord[1],
score, explode_locations, enemy_cord, enemy2_cord)
self.affected_area(bombcord[0], bombcord[1] - 4,
score, explode_locations, enemy_cord, enemy2_cord)
self.affected_area(bombcord[0], bombcord[1] + 4,
score, explode_locations, enemy_cord, enemy2_cord)
for p in explode_locations:
Matrix[p[0]][p[1]] = 'e'
bomb_location = []
for i in range(2):
for j in range(4):
bomb_location.append([bombcord[0] + i, bombcord[1] + j])
for p in bomb_location: # Clean the bomb_location
if((Matrix[p[0]][p[1]] is 0) or
(Matrix[p[0]][p[1]] is '[') or
(Matrix[p[0]][p[1]] is ']') or
(Matrix[p[0]][p[1]] is 1)):
Matrix[p[0]][p[1]] = ' '
bombcord[0] = 0
bombcord[1] = 0