-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.py
More file actions
87 lines (79 loc) · 2.59 KB
/
enemy.py
File metadata and controls
87 lines (79 loc) · 2.59 KB
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
from person import person
from random import randint
class enemy(person):
# note un is a list of unoccupied places in the dic and oc is vice-versa
def __init__(self, un, oc, dic, user):
disguise = 'E'
length = len(un)
# 2 is taken as at position 1 bomberman spawns
ran = randint(2, length - 1)
x = un[ran][0]
y = un[ran][1]
un.remove([x, y])
oc.append([x, y])
person.__init__(self, x, y, dic, disguise, user)
self._dir = {}
self._user = user
self._stop = 0
def stopme(self):
self._stop = 1
def give_status(self):
if self._stop == 0: # means not stoped
return True
else:
return False
def direction(self):
# l,u,r,d
if self._y > 8 and self._dic[self._x, self._y + 4] in (" ", "B"):
self._dir[0] = 1
else:
self._dir[0] = 0
if self._x > 4 and self._dic[self._x - 2, self._y] in (" ", "B"):
self._dir[1] = 1
else:
self._dir[1] = 0
if self._y < 69 and self._dic[self._x, self._y + 4] in (" ", "B"):
self._dir[2] = 1
else:
self._dir[2] = 0
if self._x < 35 and self._dic[self._x + 2, self._y] in (" ", "B"):
self._dir[3] = 1
else:
self._dir[3] = 0
def give(self):
return self._dic
def random_move(self, immortal):
self.direction()
count = 0
ret = -1
helper = {}
for i in self._dir:
if self._dir[i] == 1:
count = count + 1
helper[count] = i
if count is not 0:
x = randint(1, count)
ret = helper[x]
if ret == -1:
pass
else:
if ret == 0:
if self._dic[self._x, self._y - 4] in ("B"):
if immortal is False:
self._user[2] = 0
self.move_left(immortal)
elif ret == 1:
if self._dic[self._x - 2, self._y] in ("B"):
if immortal is False:
self._user[2] = 0
self.move_up(immortal)
elif ret == 2:
if self._dic[self._x, self._y + 4] in ("B"):
if immortal is False:
self._user[2] = 0
self.move_right(immortal)
else:
if self._dic[self._x + 2, self._y] in ("B"):
if immortal is False:
self._user[2] = 0
self.move_down(immortal)