-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.py
More file actions
336 lines (331 loc) · 16.3 KB
/
Copy pathPlayer.py
File metadata and controls
336 lines (331 loc) · 16.3 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
from Weapons import Weapon, Staff
from Dungeon_Crawler import player_State
from random import randint, choice
from Spells_and_Special_moves import Spell, Healing,spark, fireball
from Enemy import Enemy, Boss
from Items import Items,Health,Mana
import pygame
import random
pygame.mixer.init()
spell_sound1 = pygame.mixer.Sound("Music/Delvin_sound_effects/18_Thunder_02.wav")
spell_sounds = [spell_sound1]
class Player():
def __init__(self,HP:int, strength:int, agility:int, intelligence:int, fortitude:int, mana:int, name:str, description:str,starter_class:str):
self.current_class=starter_class
self.strength = strength
self.agility = agility
self.intelligence = intelligence
self.fortitude = fortitude
self.name = name
self.description = description
self.learned_spells=[]
basic_dagger=Weapon(10,"Dagger","Common","Basic Dagger")
basic_spear=Weapon(3,"Spear","Common","Basic Spear")
basic_sword=Weapon(5,"Sword","Common","Basic Sword")
basic_staff=Staff(3,"Staff","Common","Basic Staff")
fist=Weapon(2,"Fist","Common","Fist")
self.exp=0
self.max_exp=100
if starter_class=="Mage":
self.intelligence+=10
self.equiped_weapon=basic_staff
self.learned_spells.append(spark)
self.learned_spells.append(fireball)
elif starter_class=="Warrior":
self.fortitude+=5
self.strength+=5
self.equiped_weapon=basic_sword
self.learned_spells.append(spark)
elif starter_class=="Thief":
self.agility+=5
self.strength+=3
self.intelligence+=2
self.equiped_weapon=basic_dagger
self.learned_spells.append(spark)
elif starter_class=="Spearman":
self.agility+=5
self.strength+=5
self.equiped_weapon=basic_spear
self.learned_spells.append(spark)
elif starter_class=="Peasant":
self.equiped_weapon=fist
self.agility+=3
self.strength+=5
self.fortitude+=5
self.intelligence-=3
self.learned_spells.append(spark)
self.mana = mana + (10 * self.intelligence)
self.HP = HP + (10*self.fortitude)
self.level = 0
self.available_stat_point=0
self.inventory=[]
def equip_weapon(self,weapon:Weapon):
if self.current_class=="Mage":
if weapon.weapon_type=="Staff":
print(f"Delvin throws away {self.equiped_weapon.name}\nDelvin also sees {self.equiped_weapon.name} get taken away by a pack of rats...")
print(f"Succesfully equipped {weapon.name}")
self.equiped_weapon=weapon
else:
print("Mages can only use Staffs!")
elif self.current_class=="Spearman":
if weapon.weapon_type=="Spear":
print(f"Delvin throws away {self.equiped_weapon.name}\nDelvin also sees {self.equiped_weapon.name} get taken away by a pack of rats...")
print(f"Succesfully equipped {weapon.name}")
self.equiped_weapon=weapon
else:
print("Spearmen can only use Spears!")
elif self.current_class=="Warrior":
if weapon.weapon_type in ("Sword","Spear"):
print(f"Delvin throws away {self.equiped_weapon.name}\nDelvin also sees {self.equiped_weapon.name} get taken away by a pack of rats...")
print(f"Succesfully equipped {weapon.name}")
self.equiped_weapon=weapon
else:
print("Warriors can only use Swords and Spears!")
elif self.current_class=="Thief":
if weapon.weapon_type=="Dagger":
print(f"Delvin throws away {self.equiped_weapon.name}\nDelvin also sees {self.equiped_weapon.name} get taken away by a pack of rats...")
print(f"Succesfully equipped {weapon.name}")
self.equiped_weapon=weapon
else:
print("Thiefs can only use Daggers!")
elif self.current_class=="Peasant":
if self.equiped_weapon.weapon_type=="Fist":
print(f"Delvin picks up {weapon.name}")
else:
print(f"Delvin throws away {self.equiped_weapon.name}\nDelvin also sees {self.equiped_weapon.name} get taken away by a pack of rats...")
print(f"Succesfully equipped {weapon.name}")
self.equiped_weapon=weapon
def add_inventory(self,item:Items):
print(f"\nDelvin picks up a {item}.\n")
self.inventory.append(item)
def open_inventory(self):
if self.inventory==[]:
print("You have no itmes in your inventory!")
return
else:
for index, item in enumerate(self.inventory):
print(f"[{index}]. {item}")
choice=input("Do you want to use an item? [Y][N]\n>").upper()
while True:
if choice=="Y":
try:
item_choice=int(input("What item do you want to use?\n> "))
if 0 <= item_choice < len(self.inventory):
chosen_item = self.inventory[item_choice]
chosen_item.use(self)
self.inventory.remove(chosen_item)
break
else:
print("Invalid item number.")
except ValueError:
print("Please enter a number.")
elif choice=="N":
print("You decide not to use anything in your inventory.")
break
else:
print("Please enter [Y] or [N].")
choice = input("> ").upper()
def learn_spell(self, spell:Spell):
self.learned_spells.append(spell)
print(f"You have succesfully learned {spell.name}!")
def get_stats(self):
self.stats = [self.strength, self.agility, self.intelligence, self.fortitude]
return self.stats
def inquire(self, object):
print(object.description)
def max_mana(self):
return 100+(5*self.intelligence)
def max_hp(self):
return 100+(10*self.fortitude)
def add_level(self,enemy:Enemy):
self.exp+=enemy.exp
if self.exp>=self.max_exp:
print("Congrats you've leveled up!")
leftover_exp=self.exp-self.max_exp
self.exp=0
self.max_exp+=100
self.exp+=leftover_exp
self.level+=1
self.available_stat_point+=5
max_hp=100+(10*self.fortitude)
self.HP=max_hp
max_mana=100+(5*self.intelligence)
self.mana=max_mana
return True
else:
print(f"You have {self.exp}exp out of {self.max_exp}exp")
def add_stat(self):
print(f"Your stats are as followed\nintelligence(int):{self.intelligence}\nstrength(str):{self.strength}\nagility(agl):{self.agility}\nfortitude(frt):{self.fortitude}")
while self.available_stat_point>0:
stat=input("What stat do you want to add to? [int],[str],[agl],[frt]\n>")
if stat.lower()=="str":
self.strength+=1
self.available_stat_point-=1
print("You succesfully added one point to strength!")
print(f"Your current strength is {self.strength}")
elif stat.lower()=="int":
self.intelligence+=1
self.available_stat_point-=1
print("You succesfully added one point to intelligence!")
print(f"Your current intelligence is {self.intelligence}")
max_mana=100+(5*self.intelligence)
self.mana=max_mana
print(f"Your max Mana is now {max_mana}")
elif stat.lower()=="frt":
self.fortitude+=1
self.available_stat_point-=1
print("You succesfully added one point to fortitude!")
print(f"Your current fortitude is {self.fortitude}")
max_hp=100+(10*self.fortitude)
self.HP=max_hp
print(f"You max HP is now {max_hp}")
elif stat.lower()=="agl":
self.agility+=1
self.available_stat_point-=1
print("You succesfully added one point to agility!")
print(f"Your current agility is {self.agility}")
else:
print("That's not a valid stat!")
def attack(self,enemy:Enemy):
if self.learned_spells==[]:
print("You chose to attack with your weapon.")
if randint(1,100)<=self.equiped_weapon.base_hit_chance+(2*self.agility):
damage=self.equiped_weapon.base_dmg+self.strength
enemy.HP-=damage
if self.equiped_weapon.weapon_type=="Fist":
print(f"You punched {enemy.name} with your fist!?")
print(f"You did {damage} damage somehow!??")
elif self.equiped_weapon.weapon_type=="Staff":
print(f"You bonked {enemy.name} with your staff!\nDealing {damage} damage (Who said mages aren't anything without magic!?)")
elif self.equiped_weapon.weapon_type in ("Dagger","Sword"):
print(f"You slashed {enemy.name} for {damage} damage!")
elif self.equiped_weapon.weapon_type=="Spear":
print(f"You poked {enemy.name} for {damage} damage!")
else:
print("You missed!")
elif self.learned_spells!=[]:
choice=input("You choose to attack with [1]weapon/[2]spell.\n>").upper()
if choice=="1":
print("You chose to attack with your weapon.")
if randint(1,100)<=self.equiped_weapon.base_hit_chance+(2*self.agility):
damage=self.equiped_weapon.base_dmg+self.strength
enemy.HP-=damage
if self.equiped_weapon.weapon_type=="Fist":
print(f"You punched {enemy.name} with your fist!?")
elif self.equiped_weapon.weapon_type=="Staff":
print(f"You bonked {enemy.name} with your staff!\nDealing {damage} (Who said mages aren't anything without magic!?)")
elif self.equiped_weapon.weapon_type in ("Dagger","Sword"):
print(f"You slashed {enemy.name} for {damage} damage!")
elif self.equiped_weapon.weapon_type=="Spear":
print(f"You poke {enemy.name} for {damage}!")
else:
print("You missed!")
elif choice=="2":
print("You chose to attack with a spell!")
for index, spell in enumerate(self.learned_spells):
print(f"[{index}]. {spell.name}")
while True:
try:
spell_choice=int(input("What spell do you want to use?\n> "))
if 0 <= spell_choice < len(self.learned_spells):
chosen_spell=self.learned_spells[spell_choice]
break
else:
print("Invalid spell number.")
except ValueError:
print("Please enter a number.")
if chosen_spell in self.learned_spells:
print(f"You try to cast {self.learned_spells[spell_choice].name}")
if randint(1,100)<=chosen_spell.accuracy+(2*self.intelligence):
if self.mana<chosen_spell.mana_cost:
print(f"You don't have enough mana to cast {chosen_spell.name}!")
else:
if self.equiped_weapon.weapon_type=="Staff":
self.mana-=(chosen_spell.mana_cost - self.equiped_weapon.mana_cost)
else:
self.mana-=chosen_spell.mana_cost
sound = random.choice(spell_sounds)
sound.play()
damage=chosen_spell.stat_amount+(round(0.5*self.intelligence))
if isinstance(chosen_spell, Healing):
self.HP+=damage
if self.HP > self.max_hp():
self.HP = self.max_hp()
print(f"You healed yourself for {damage} points!")
else:
enemy.HP-=damage
print(f"You did {damage} damage!")
else:
if self.equiped_weapon.weapon_type=="Staff":
self.mana-=(chosen_spell.mana_cost - self.equiped_weapon.mana_cost)
else:
self.mana-=chosen_spell.mana_cost
if isinstance(chosen_spell, Healing):
print("You can't even heal yourself right!?")
else:
print("The spell missed!")
delvin=Player(100,100,100,100,100,100,"Big Delvin","God Mode delvin","Warrior")
# class Warrior(Player):
# def __init__(self, HP, strength, agility, intelligence, fortitude, mana, name, description):
# super().__init__(HP, strength, agility, intelligence, fortitude, mana, name, description)
# basic_sword=Weapon(5,"Sword","Common")
# self.equiped_weapon=basic_sword
# self.strength+=5
# self.fortitude+=5
# def class_hp(self):
# self.HP=100+(10*self.fortitude)
# def equip_weapon(self,weapon:Weapon):
# if weapon.weapon_type in ("Spear","Sword"):
# self.equiped_weapon=weapon
# else:
# print("Warriors can only use Spears and Swords.")
# class Thief(Player):
# def __init__(self, HP, strength, agility, intelligence, fortitude, mana, name, description):
# super().__init__(HP, strength, agility, intelligence, fortitude, mana, name, description)
# self.agility+=5
# self.intelligence+=3
# self.strength+=2
# basic_dagger=Weapon(10,"Dagger","Common")
# self.equiped_weapon=basic_dagger
# def class_hp(self):
# self.HP=100+(10*self.fortitude)
# def class_mana(self):
# self.mana=100+(5*self.fortitude)
# def equip_weapon(self,weapon:Weapon):
# if weapon.weapon_type == "Dagger":
# self.equiped_weapon=weapon
# else:
# print("Theifs can only use Daggers.")
# class Spearman(Player):
# def __init__(self, HP, strength, agility, intelligence, fortitude, mana, name, description):
# super().__init__(HP, strength, agility, intelligence, fortitude, mana, name, description)
# self.strength+=5
# self.agility+=5
# basic_spear=Weapon(3,"Spear","Common")
# self.equiped_weapon=basic_spear
# def equip_weapon(self,weapon:Weapon):
# if weapon.weapon_type == "Spear":
# self.equiped_weapon=weapon
# else:
# print("Spearmen can only use Spears.")
# class Peasant(Player):
# def __init__(self, HP, strength, agility, intelligence, fortitude, mana, name, description):
# super().__init__(HP, strength, agility, intelligence, fortitude, mana, name, description)
# self.equiped_weapon=None
# def equip_weapon(self,weapon:Weapon):
# self.equiped_weapon=weapon
# class Mage(Player):
# def __init__(self, HP, strength, agility, intelligence, fortitude, mana, name, description):
# super().__init__(HP, strength, agility, intelligence, fortitude, mana, name, description)
# self.intelligence+=10
# basic_staff=Staff(3,"Staff","Common")
# self.equiped_weapon=basic_staff
# def class_mana(self):
# self.mana=100+(5*self.intelligence)
# def equip_weapon(self, weapon:Weapon):
# if weapon.weapon_type=="Staff":
# self.equiped_weapon=weapon
# else:
# print("You fool I'm a mage not a Barbarian!\n(Mages can only equip Staffs)")
# player1=Player(100,0,0,0,0,100,"Delvin","asdasda","Warrior")
# print(player1.HP, player1.strength, player1.fortitude, player1.equiped_weapon_type)