-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.py
More file actions
279 lines (207 loc) · 12.4 KB
/
Copy pathmain.py
File metadata and controls
279 lines (207 loc) · 12.4 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
from classes.game import bcolors, Person
from classes.magic import Spell
from classes.inventory import Item
import random
# BLACK MAGIC spells
fire = Spell(name = "Fire", cost = 25, dmg = 600, type = "Black")
thunder = Spell(name = "Thunder", cost = 25, dmg = 620, type = "Black")
blizzard = Spell(name ="Blizzard", cost = 25, dmg = 640, type = "Black")
meteor = Spell(name = "Meteor", cost = 30, dmg = 760, type = "Black")
quake = Spell(name = "Quake", cost = 38, dmg = 780, type = "Black")
# WHITE MAGIC spells
heal = Spell(name = "Heal", cost = 25, dmg = 1200, type = "White")
cure = Spell(name = "Cure", cost = 40, dmg = 2000, type = "White")
# CREATE SOME ITEMS
potion = Item(name = "Potion", type = "potion", description = "Heals 50 HP", prop = 50)
hipotion = Item(name = "Hi-Potion", type = "potion", description = "Heals 100 HP", prop = 100)
superpotin = Item(name = "Super-Potion", type = "potion", description = "Heals 500 HP", prop = 1000)
elixir = Item(name = "Elixir", type = "elixir", description = "Fully restores HP/MP of one party member", prop = 9999)
hielixir = Item(name = "Mega-Elixir", type = "elixir", description = "Fully restores party's HP/MP", prop = 9999)
grenade = Item(name = "Grenade", type = "attack", description = "Deals 800 damage", prop = 800)
# DECLARATION OF THE PLAYERS
player_spells = [meteor, quake, blizzard, cure, heal]
enemy_spells = [fire, meteor, thunder, heal]
player_items = [{"item": potion, "qty": 15},
{"item": hipotion, "qty": 5},
{"item": superpotin, "qty": 5},
{"item": elixir, "qty": 5},
{"item": hielixir, "qty": 2},
{"item": grenade, "qty": 5}]
# MULTI-PLAYER DECLARATION
player1 = Person(name = "Khyati", hp = 5234, mp = 150, atk = 400, df = 34, magic = player_spells, items = player_items) # name, hp, mp, atk, df, magic, items
player2 = Person(name = "Himani", hp = 3440, mp = 350, atk = 333, df = 34, magic = player_spells, items = player_items)
player3 = Person(name = "Saumya", hp = 6460, mp = 100, atk = 558, df = 34, magic = player_spells, items = player_items)
players = [player1, player2, player3]
enemy1 = Person(name = "Witcher", hp = 18200, mp = 300, atk = 530, df = 525, magic = enemy_spells, items = [])
enemy2 = Person(name = "Magus ", hp = 1250, mp = 250, atk = 650, df = 25, magic = enemy_spells, items = [])
enemy3 = Person(name = "Serpent", hp = 1550, mp = 351, atk = 430, df = 425, magic = enemy_spells, items = [])
enemies = [enemy2, enemy1, enemy3]
running = True
i = 0
print()
print(bcolors.BOLD + bcolors.WARNING + " LET'S BEGIN !!!" + bcolors.ENDC)
while running:
print("=====================================================================================")
print()
print(bcolors.BOLD + bcolors.OKBLUE + "Names: HP MP" + bcolors.ENDC)
for player in players:
player.get_status()
print("\n")
for enemy in enemies:
enemy.get_enemy_status()
for player in players:
print("\n")
player.choose_action()
choice = input("\t" + bcolors.CYAN + "Choose action: " + bcolors.ENDC)
index = int(choice) - 1
# PLAYER IN ATTACK MODE
if index == 0:
dmg = player.generate_damage()
enemy = player.choose_target(enemies)
enemies[enemy].take_damage(dmg)
print()
print("You attacked " + enemies[enemy].name.replace(" ", "") + " for " + bcolors.BOLD + bcolors.FAIL + str(dmg) + bcolors.ENDC + " points of damage.")
if enemies[enemy].get_hp() == 0:
print(enemies[enemy].name.replace(" ", "") + " is dead now.")
del enemies[enemy]
# CHECK IF BATTLE IS OVER
if len(enemies) == 0:
print("=====================================================================================")
print(bcolors.OKGREEN + bcolors.BOLD + " YOU WON !" + bcolors.ENDC)
print("=====================================================================================")
exit()
if len(players) == 0:
print("=====================================================================================")
print(bcolors.FAIL + bcolors.BOLD + " ENEMIES HAVE DEFEATED YOU !" + bcolors.ENDC)
print("=====================================================================================")
exit()
print()
# PLAYER IN MAGIC MODE
elif index == 1:
player.choose_magic()
magic_choice = int(input("\t" + bcolors.CYAN + "Choose magic spell: " + bcolors.ENDC)) - 1
if magic_choice == -1:
continue
spell = player.magic[magic_choice]
magic_dmg = spell.generate_damage()
current_mp = player.get_mp()
if current_mp < spell.cost:
print(bcolors.FAIL + "\nYou do not have enough magic points" + bcolors.ENDC)
continue
player.reduce_mp(spell.cost)
if spell.type == "White":
player.heal(magic_dmg)
print(bcolors.OKGREEN + "\n" + spell.name + " heals for " + str(magic_dmg) + " health pints." + bcolors.ENDC)
elif spell.type == "Black":
enemy = player.choose_target(enemies)
enemies[enemy].take_damage(magic_dmg)
print(bcolors.OKBLUE + "\n" + spell.name + " deals", str(magic_dmg), "points of damage to " + enemies[enemy].name.replace(" ", "") + bcolors.ENDC)
if enemies[enemy].get_hp() == 0:
print(enemies[enemy].name.replace(" ", "") + " is dead now.")
del enemies[enemy]
# CHECK IF BATTLE IS OVER
if len(enemies) == 0:
print("=====================================================================================")
print(bcolors.OKGREEN + bcolors.BOLD + " YOU WON !" + bcolors.ENDC)
print("=====================================================================================")
exit()
if len(players) == 0:
print("=====================================================================================")
print(bcolors.FAIL + bcolors.BOLD + " ENEMIES HAVE DEFEATED YOU !" + bcolors.ENDC)
print("=====================================================================================")
exit()
# PLAYER IN ITEM MODE
elif index == 2:
player.choose_item()
item_choice = int(input("\t" + bcolors.CYAN + "Choose item: " + bcolors.ENDC)) - 1
if item_choice == -1:
continue
item = player.items[item_choice]["item"]
if player.items[item_choice]["qty"] == 0:
print(bcolors.FAIL + "\nNone left......" + bcolors.ENDC)
continue
player.items[item_choice]["qty"] -= 1
if item.type == "potion":
player.heal(item.prop)
print("\n" + bcolors.OKGREEN + item.name + " heals for " + str(item.prop) + " HP" + bcolors.ENDC)
elif item.type == "elixir":
if item.name == "Mega-Elixir":
for i in players:
i.hp = i.maxhp
i.mp = i.maxmp
else:
player.hp = player.maxhp
player.mp = player.maxmp
print("\n" + bcolors.OKGREEN + item.name + "Fully restores HP/MP" + bcolors.ENDC)
elif item.type == "attack":
enemy = player.choose_target(enemies)
enemies[enemy].take_damage(item.prop)
print("\n" + bcolors.FAIL + item.name + " deals " + str(item.prop) + " points of damage to " + enemies[enemy].name.replace(" ", "") + bcolors.ENDC)
if enemies[enemy].get_hp() == 0:
print(enemies[enemy].name.replace(" ", "") + " is dead now.")
del enemies[enemy]
# CHECK IF BATTLE IS OVER
if len(enemies) == 0:
print("=====================================================================================")
print(bcolors.OKGREEN + bcolors.BOLD + " YOU WON !" + bcolors.ENDC)
print("=====================================================================================")
exit()
if len(players) == 0:
print("=====================================================================================")
print(bcolors.FAIL + bcolors.BOLD + " ENEMIES HAVE DEFEATED YOU !" + bcolors.ENDC)
print("=====================================================================================")
exit()
# ENEMY IN ACTION
for enemy in enemies:
enemy_choice = random.randrange(0, 2)
target = random.randrange(0, len(players))
# ENEMY IN ATTACK MODE
if enemy_choice == 0:
enemy_dmg = enemy.generate_damage()
players[target].take_damage(enemy_dmg)
print(enemy.name.replace(" ", "") + " has attacked " + players[target].name + " for " + bcolors.BOLD + bcolors.FAIL + str(enemy_dmg) + bcolors.ENDC + " points of damage.")
print()
if players[target].get_hp() == 0:
print(players[target].name + " is dead now.")
del players[target]
# CHECK IF BATTLE IS OVER
if len(enemies) == 0:
print("=====================================================================================")
print(bcolors.OKGREEN + bcolors.BOLD + " YOU WON !" + bcolors.ENDC)
print("=====================================================================================")
exit()
if len(players) == 0:
print("=====================================================================================")
print(bcolors.FAIL+ bcolors.BOLD + " ENEMIES HAVE DEFEATED YOU !" + bcolors.ENDC)
print("=====================================================================================")
exit()
# ENEMY IN MAGIC MODE
elif enemy_choice == 1:
magic_choice = random.randrange(0, len(enemy.magic))
spell = enemy.magic[magic_choice]
magic_dmg = spell.generate_damage()
current_mp = enemy.get_mp()
if current_mp < spell.cost:
print(bcolors.FAIL + "\nYou do not have enough magic points" + bcolors.ENDC)
continue
enemy.reduce_mp(spell.cost)
if spell.type == "White":
enemy.heal(magic_dmg)
print(bcolors.OKGREEN + "\n" + spell.name + " heals for " + str(magic_dmg) + " health points." + bcolors.ENDC)
elif spell.type == "Black":
players[target].take_damage(magic_dmg)
print(bcolors.OKBLUE + "\n" + spell.name + " deals", str(magic_dmg), "points of damage to " + players[target].name.replace(" ", "") + bcolors.ENDC)
if players[target].get_hp() == 0:
print(players[target].name.replace(" ", "") + " is dead now.")
del players[target]
# CHECK IF BATTLE IS OVER
if len(enemies) == 0:
print("=====================================================================================")
print(bcolors.OKGREEN + bcolors.BOLD + " YOU WON !" + bcolors.ENDC)
print("=====================================================================================")
exit()
if len(players) == 0:
print("=====================================================================================")
print(bcolors.FAIL + bcolors.BOLD + " ENEMIES HAVE DEFEATED YOU !" + bcolors.ENDC)
print("=====================================================================================")
exit()