-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassCharacter.py
More file actions
298 lines (267 loc) · 13 KB
/
classCharacter.py
File metadata and controls
298 lines (267 loc) · 13 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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#create dictionaries for characters with values that change as user interacts
import random
import time
from tools import slow_print
class Character:
def __init__(self, name, health, max_health, stamina, max_stamina, power, defence, agility, reflexes, xp, coins, crowd, never, berserk, rank):
self.name = name
self.health = health
self.max_health = max_health
self.stamina = health
self.max_stamina = max_stamina
self.power = power
self.defence = defence
self.agility = agility
self.reflexes = reflexes
self.xp = xp
self.coins = coins
self.crowd = crowd
self.never = never
self.berk = berserk
self.rank = rank
def is_alive(self):
return self.health > 0
def punch(self, enemy):
if not self.is_alive():
return
print(f"{self.name} tries to punch {enemy.name}.\n")
time.sleep(1)
if self.stamina < 5:
print(f"{self.name} is worn out and stumbles to the ground!")
else:
if self.attack_hit(enemy) == False:
print(f"{enemy.name} dodges!\n")
else:
probability_threshold = 0.25
if random.random() < probability_threshold:
print(f"{self.name} lands a MASSIVE blow!")
damage_given = int(int(random.randint(int(int(self.power) / 2), int(int(self.power)) * 2)) - int(random.randint(1, int(enemy.defence) / 2)))
if damage_given < (int(self.power) / 2):
damage_given = int(int(self.power) / 2)
damage_given = int(damage_given)
print(f"{self.name} deals {damage_given} damage.\n")
enemy.receive_damage(damage_given)
else:
print(f"{self.name} lands a regular blow!")
damage_given = int(int(random.randint(int(int(self.power) / 2), int(self.power)) * 1) - int(random.randint(1, int(enemy.defence) / 2)))
damage_given = int(damage_given)
if damage_given < (int(self.power) / 2):
damage_given = int(int(self.power) / 2)
print(f"{self.name} deals {damage_given} damage.\n")
enemy.receive_damage(damage_given)
self.stamina -= 5
if self.stamina < 0:
self.stamina = 0
time.sleep(1)
def kick(self, enemy):
if not self.is_alive():
return
print(f"{self.name} tries to kick {enemy.name}.\n")
time.sleep(1)
if self.stamina < 10:
print(f"{self.name} is worn out and stumbles to the ground!")
else:
if self.attack_hit(enemy) == False:
print(f"{enemy.name} dodges!\n")
else:
probability_threshold = 0.50
if random.random() < probability_threshold:
print(f"{self.name} lands a MASSIVE kick!")
damage_given = int(int(random.randint(int(int(self.power) / 2), int(int(self.power)) * 3)) - int(random.randint(1, int(int(enemy.defence) / 2))))
damage_given = int(damage_given)
if damage_given < (int(self.power) / 2):
damage_given = int(int(self.power) / 2)
damage_given = int(damage_given)
print(f"{self.name} deals {damage_given} damage.\n")
enemy.receive_damage(damage_given)
else:
print(f"{self.name} lands a regular kick!")
damage_given = int(int(random.randint(int(int(self.power) / 2), int(int(self.power)) * 1)) - int(random.randint(1, int(enemy.defence) / 2)))
damage_given = int(damage_given)
if damage_given < (int(self.power) / 2):
damage_given = int(int(self.power) / 2)
print(f"{self.name} deals {damage_given} damage.\n")
enemy.receive_damage(damage_given)
self.stamina -= 15
if self.stamina < 0:
self.stamina = 0
time.sleep(1)
def attack_hit(self, enemy):
if random.randint(int(int(self.agility)/2), int(self.agility)) - random.randint(1, int(int(enemy.reflexes))) > 0:
return True
def receive_damage(self, points):
self.health -= points
if self.health < 0:
self.health = 0
def is_knockout(self, hero):
print(f"You are victorious! You gain {self.xp} XP and {self.coins} COINS.\n")
hero.xp += self.xp
return hero.xp
hero.coins += self.coins
return hero.coins
def heal_hp(self, points):
self.health += points
if self.health > self.max_health:
self.health = self.max_health
return self.health
return self.health
def heal_sp(self, points):
self.stamina += points
if self.stamina > self.max_stamina:
self.stamina = self.max_stamina
return self.stamina
def print_status(self):
print(f"{self.name} currently has {self.health} of {self.max_health} HEALTH POINTS and {self.stamina} of {self.max_stamina} STAMINA POINTS with the following stats:\n\n * POWER: {self.power} • DEFENCE: {self.defence}\n * AGILITY: {self.agility} • REFLEXES: {self.reflexes}\n")
def do_crowd_favorite(self):
if self.rank == 1:
self.stamina += 0.05 * self.stamina
elif self.rank == 2:
self.stamina += 0.10 * self.stamina
elif self.rank == 3:
self.stamina += 0.15 * self.stamina
def do_berserker(self):
if self.rank == 1:
self.stamina += 0.05 * self.stamina
elif self.rank == 2:
self.stamina += 0.10 * self.stamina
elif self.rank == 3:
self.stamina += 0.15 * self.stamina
def do_never_give_up(self):
if self.rank == 1:
self.stamina += 0.05 * self.stamina
elif self.rank == 2:
self.stamina += 0.10 * self.stamina
elif self.rank == 3:
self.stamina += 0.15 * self.stamina
class Hero(Character):
def __init__(self, name, health, max_health, stamina, max_stamina, power, defence, agility, reflexes, xp, coins, crowd, never, berserk, rank, lvl, lvl_2, lvl_3, lvl_4, lvl_5, lvl_6, lvl_7, lvl_8, lvl_9, lvl_10, lvl_11, lvl_12):
super().__init__(name, health, max_health, stamina, max_stamina, power, defence, agility, reflexes, xp, coins, crowd, never, berserk, rank)
self.lvl = lvl
self.items = []
self.gear = []
self.power = power
self.lvl_2 = lvl_2
self.lvl_3 = lvl_3
self.lvl_4 = lvl_4
self.lvl_5 = lvl_5
self.lvl_6 = lvl_6
self.lvl_7 = lvl_7
self.lvl_8 = lvl_8
self.lvl_9 = lvl_9
self.lvl_10 = lvl_10
self.lvl_11 = lvl_11
self.lvl_12 = lvl_12
def lvl_evolution(self):
if self.lvl == 1 and self.xp >= self.lvl_2:
print("CONGRATULATIONS!\nYou reached Level 2!")
self.add_stats()
elif self.lvl == 2 and self.xp >= self.lvl_3:
print("CONGRATULATIONS!\nYou reached Level 3!")
self.add_stats()
elif self.lvl == 3 and self.xp >= self.lvl_4:
print("CONGRATULATIONS!\nYou reached Level 4!")
self.add_stats()
elif self.lvl == 4 and self.xp >= self.lvl_5:
print("CONGRATULATIONS!\nYou reached Level 5!")
self.add_stats()
elif self.lvl == 5 and self.xp >= self.lvl_6:
print("CONGRATULATIONS!\nYou reached Level 6!")
self.add_stats()
elif self.lvl == 6 and self.xp >= self.lvl_7:
print("CONGRATULATIONS!\nYou reached Level 7!")
self.add_stats()
elif self.lvl == 7 and self.xp >= self.lvl_8:
print("CONGRATULATIONS!\nYou reached Level 8!")
self.add_stats()
elif self.lvl == 8 and self.xp >= self.lvl_9:
print("CONGRATULATIONS!\nYou reached Level 9!")
self.add_stats()
elif self.lvl == 9 and self.xp >= self.lvl_10:
print("CONGRATULATIONS!\nYou reached Level 10!")
self.add_stats()
def add_stats(self):
self.lvl += 1
endurance_question_answered = False
skill_question_answered = False
while endurance_question_answered == False:
print("You have 10 additional ENDURANCE POINTS to spread between HEALTH & STAMINA.\n")
add_health = int(input("How many do you want for HEALTH?\n> "))
add_stamina = int(input("How many do you want for STAMINA?\n> "))
if add_health + add_stamina > 10:
print("That's more than 10! Let's try again.")
print()
endurance_question_answered = False
elif add_health + add_stamina < 10:
print("That's less than 10! Let's try again.")
print()
endurance_question_answered = False
else:
redo_endurance = input(f"\nYou have chosen:\n\n * {add_health} for HEALTH\n * {add_stamina} for STAMINA\n\n1 — REDO\n2 — ACCEPT!\n> ")
if redo_endurance == "1":
endurance_question_answered = False
elif redo_endurance == "2":
endurance_question_answered = True
else:
print("That is an incorrent entry. Let's try again!\n")
endurance_question_answered = False
self.max_health += add_health
self.health = self.max_health
self.max_stamina += add_stamina
self.stamina = self.max_stamina
print(f"\nYour MAX HP rises to {self.max_health} and your MAX SP to {self.max_stamina}.\nYou also FULLY HEAL!")
time.sleep(3)
print("Now let's move on to your SKILLS...")
time.sleep(2)
print("\nYou have 4 POINTS available to spread among: \n\n * POWER & DEFENCE for your overall STRENGTH, \n * AGILITY & REFLEXES for your overall SWIFTNESS.")
print()
while skill_question_answered == False:
add_power = int(input("How many do you want for POWER?\n> "))
add_defence = int(input("How many do you want for DEFENCE?\n> "))
add_agility = int(input("How many do you want for AGILITY?\n> "))
add_reflexes = int(input("How many do you want for REFLEXES?\n> "))
if add_power + add_defence + add_agility + add_reflexes > 4:
print("\nThat's more than 4! Let's try again.")
print()
skill_question_answered = False
elif add_power + add_defence + add_agility + add_reflexes < 4:
print("\nThat's less than 4! Let's try again.")
print()
skill_question_answered = False
else:
redo_skills = input(f"\nYou have chosen:\n\n * {add_power} for POWER,\n * {add_defence} for DEFENCE, \n * {add_agility} for AGILITY,\n * {add_reflexes} for REFLEXES.\n\n1 — REDO\n2 — ACCEPT!\n> ")
if redo_skills == "1":
skill_question_answered = False
elif redo_skills == "2":
skill_question_answered = True
else:
print("That is an incorrent entry. Let's try again!\n")
skill_question_answered = False
self.power = int(self.power) + int(add_power)
self.defence = int(self.defence) + int(add_defence)
self.agility = int(self.agility) + int(add_agility)
self.reflexes = int(self.reflexes) + int(add_reflexes)
print("\nCONGRATULATIONS! \n\nHere are your upgraded stats:")
time.sleep(2)
print()
print(f" * MAX HEALTH: {self.max_health}")
print(f" * MAX STAMINA: {self.max_stamina}")
print(f" * POWER: {self.power}")
print(f" * DEFENCE: {self.defence}")
print(f" * AGILITY: {self.agility}")
print(f" * REFLEXES: {self.reflexes}")
time.sleep(2)
def do_guard(self):
health_up = random.randint(int(int(self.defence) / 2), self.defence)
self.health += health_up
if self.health > self.max_health:
self.health = self.max_health
stamina_up = random.randint(int(int(self.reflexes) / 2), self.reflexes)
self.stamina += stamina_up
if self.stamina > self.max_stamina:
self.stamina = self.max_stamina
print(f"{self.name} guarded and healed {health_up} HP and recovered {stamina_up} SP!\n")
def use_item(self, item):
item.apply(hero)
class Opponent(Character):
def __init__(self, name, health, max_health, stamina, max_stamina, power, defence, agility, reflexes, xp, coins, crowd, never, berserk, rank):
super().__init__(name, health, max_health, stamina, max_stamina, power, defence, agility, reflexes, xp, coins, crowd, never, berserk, rank)