-
Notifications
You must be signed in to change notification settings - Fork 0
/
person.py
140 lines (120 loc) · 3.76 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
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
"""
Module for definition of Mario and enemies
"""
import common
import movement
import check
import config
import thing
import sound
# for mario and enemy , this is the core class
# inheritance
class Person(thing.Thing):
"""
Common class for Mario and Enemy
"""
def __init__(self, x, y):
super().__init__(x, y)
# private functions specific for enemy and Mario
self.__check()
def move(self, x, y='?', who='?'):
super().move(x, y, who)
self.__check()
def jump(self):
"""
Mario can jump
"""
self.move(self.x_pos+3, self.y_pos-3)
# drop is for gravity effect - mario and enemy - when they fall into a pit/gap
def __check(self):
if self.y_pos >= common.MIDS_R and common.value_arr(self.x_pos, self.y_pos+1) != '0':
if self.y_pos > (common.MIDS_R + 3):
raise config.GapHere
else:
self.move(self.x_pos, self.y_pos+1)
class Mario(Person):
"""
Mario main character
"""
def __init__(self, x, y):
super().__init__(x, y)
self.print_out()
def move(self, x, y):
# when Mario hits the Marijuana
if common.value_arr(x, y) == "$":
sound.play_sound("mb_sc.wav")
for i in config.M_LIST:
if i.x_pos == x or i.x_pos == x+1 or i.x_pos == x-1:
if i.y_pos == y or i.y_pos == y+1 or i.y_pos == y-1:
config.POINTS += 20
config.M_LIST.remove(i)
try:
if (x > common.R3 and x < common.R4):
check.check_life(x, y, "Mario")
self.refresh_out()
super().move(x, y)
self.print_out()
else:
movement.move_all(x-self.x_pos)
check.check_life(self.x_pos, y, "Mario")
self.refresh_out()
super().move(self.x_pos, y, "Mario")
self.print_out()
except config.GapHere:
raise config.DeadMario from None
def print_out(self):
"""
update the coordinates
"""
common.set_arr(self.x_pos, self.y_pos, "I")
common.set_arr(self.x_pos, self.y_pos-1, "O")
common.set_arr(self.x_pos, self.y_pos-2, "^")
def refresh_out(self):
"""
refresh the coordinates
"""
for i in range(-2, 1):
common.reset_arr(self.x_pos, self.y_pos+i)
class Enemy(Person):
"""
Enemy , points for killing it
"""
def __init__(self, x, y):
super().__init__(x, y)
self.print_out()
# over-riding
def move(self, x, y):
try:
check.check(x, y, "Enemy")
self.refresh_out()
super().move(x, y)
self.print_out()
except (config.GapHere, config.TouchBoundary):
config.E_LIST.remove(self)
self.refresh_out()
except config.WallHere:
pass
except config.MarioAbove:
# enemy getting killed because of mario jumping on it
sound.play_sound("mb_touch.wav")
config.E_LIST.remove(self)
self.refresh_out()
config.POINTS += 10
except config.DeadMario:
config.M.refresh_out()
self.refresh_out()
super().move(x, y)
self.print_out()
raise config.DeadMario from None
def refresh_out(self):
"""
refresh the coordinates
"""
common.reset_arr(self.x_pos, self.y_pos)
common.reset_arr(self.x_pos+1, self.y_pos)
def print_out(self):
"""
update the coordinates
"""
common.set_arr(self.x_pos, self.y_pos, ">")
common.set_arr(self.x_pos+1, self.y_pos, "<")