-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperson.py
63 lines (54 loc) · 1.95 KB
/
person.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
class Person:
""" Person class which is inherited by Bomber and Enemy contains functions related to movement etc."""
def __init__(self, x, y):
self._position = [x, y]
def setPosition(self, x, y):
self._position = [x, y]
def getPosition(self):
return self._position
def InsertPerson(self, array):
[x, y] = self.getPosition()
if (array[y][x] != ' ' and array[y][x] != 'B'):
return 0
for p in range(4):
array[y][x + p] = self._shape[0][p]
array[y + 1][x + p] = self._shape[1][p]
def RemovePerson(self, array):
[x, y] = self.getPosition()
if (array[y + 1][x] == '['):
return 0
for p in range(4):
array[y][x + p] = ' '
array[y + 1][x + p] = ' '
def moveRight(self, array):
[x, y] = self.getPosition()
if (array[y][x + 4] != ' ' and array[y][x + 4] != '['
and array[y][x + 4] != 'E' and array[y][x + 4] != 'B'):
return 0
else:
self.setPosition(x + 4, y)
return 1
def moveLeft(self, array):
[x, y] = self.getPosition()
if (array[y][x - 4] != ' ' and array[y][x - 4] != '['
and array[y][x - 4] != 'E' and array[y][x - 4] != 'B'):
return 0
else:
self.setPosition(x - 4, y)
return 1
def moveUp(self, array):
[x, y] = self.getPosition()
if (array[y - 2][x] != ' ' and array[y - 2][x] != '['
and array[y - 2][x] != 'E' and array[y - 2][x] != 'B'):
return 0
else:
self.setPosition(x, y - 2)
return 1
def moveDown(self, array):
[x, y] = self.getPosition()
if (array[y + 2][x] != ' ' and array[y + 2][x] != '['
and array[y + 2][x] != 'E' and array[y + 2][x] != 'B'):
return 0
else:
self.setPosition(x, y + 2)
return 1