-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_of_mana_party_test.py
634 lines (580 loc) · 24.5 KB
/
text_of_mana_party_test.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
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
import the_map
import sys
import os
import random
from ast import literal_eval
import time
from Q2API.util import logging
import traceback
import pygame, pygame.mixer
logger = logging.out_file_instance("Secret_of_Texts")
rooms_by_name = dict()
player_inventory =[]
game_map = None
sword_count = 1
wallet = 0
score = 0
party = []
def main():
global game_map
games = os.listdir("saved_games")
pygame.mixer.init()
pygame.init()
sound = pygame.mixer.Sound('Secret_of_Mana_Opening_Theme.wav')
sound.play()
if games:
for i, file_name in enumerate(games):
print str(i) + "\t" + file_name.split(".")[0]
choice = raw_input("choose a game or type 'N' for a new game\n>")
if choice not in ["N", "n", "new", "NEW"]:
try:
game_file = "saved_games\\" + games[int(choice)]
except:
print "you failed to type a number. HOW?!?"
exit()
else:
game_file = 'the_map.xml'
else:
game_file = 'the_map.xml'
with open(game_file, 'r') as fin:
xml_file = fin.read()
success, game_map = the_map.obj_wrapper(xml_file)
# build a dictionary that maps room names to room objects
global rooms_by_name
for room in game_map.building:
room_name = room.attrs["room"]
rooms_by_name[room_name] = room
# initialize the starting room
global player
player = game_map.player[0]
last_room = None
starting_room = int(player.attrs["room"])
current_room = game_map.building[starting_room]
intro()
overworld_music(room)
while True:
if current_room is not last_room:
describe(current_room)
last_room = current_room
command = raw_input(">")
verb, noun = parse_command(command)
os.system('CLS')
current_room = run_command(current_room, verb, noun)
def battle_music(number, room):
pygame.mixer.fadeout(500)
if room.monster[0].attrs['name'] == 'Dark Lich':
pygame.mixer.init()
pygame.init()
sound = pygame.mixer.Sound('The_Oracle_Dark_Lich_Secret_of_Mana.wav')
sound.set_volume(.35)
if number == 0:
sound.play()
elif number == 1:
pygame.mixer.fadeout(500)
overworld_music(room)
else:
pygame.mixer.fadeout(500)
overworld_music(room)
elif room.monster[0].attrs['name'] == 'Mana Beast':
pygame.mixer.init()
pygame.init()
sound = pygame.mixer.Sound('Secret_of_Mana_Meridian_Dance_sound_remastered_.wav')
if number == 0:
sound.play()
elif number == 1:
pygame.mixer.fadeout(500)
overworld_music(room)
else:
pygame.mixer.fadeout(500)
overworld_music(room)
else:
if room.monster[0].attrs['boss'] == 'True':
pygame.mixer.init()
pygame.init()
sound = pygame.mixer.Sound('Secret_of_Mana_Dangers.wav')
if number == 0:
sound.play()
elif number == 1:
pygame.mixer.fadeout(500)
overworld_music(room)
else:
pygame.mixer.fadeout(500)
overworld_music(room)
else:
pygame.mixer.init()
pygame.init()
sound = pygame.mixer.Sound('Battle Theme.wav')
if number == 0:
sound.play()
sound.set_volume(.15)
elif number == 1:
pygame.mixer.fadeout(500)
overworld_music(room)
else:
pygame.mixer.fadeout(500)
overworld_music(room)
def party_builder(room):
global game_map
global Randi
global Purim
global Popoie
global party
Randi = {'Name': game_map.player[0].attrs['name'], 'Player Level': game_map.player[0].attrs['level'], 'Player Exp': game_map.player[0].attrs['playerxp'], 'Next Level': game_map.player[0].attrs['Nextlvl'], 'player_stats' : {'Strength': game_map.player[0].attrs['strength'], 'Dexterity': game_map.player[0].attrs['dexterity'], 'Endurance': game_map.player[0].attrs['endurance'], 'attack' :game_map.player[0].attrs['attack1'], 'health': 100}}
Purim = {'Name': game_map.player[1].attrs['name'],'Player Level': game_map.player[1].attrs['level'], 'Player Exp': game_map.player[1].attrs['playerxp'], 'Next Level': game_map.player[1].attrs['Nextlvl'], 'player_stats' : {'Strength': game_map.player[1].attrs['strength'], 'Dexterity': game_map.player[1].attrs['dexterity'], 'Endurance': game_map.player[1].attrs['endurance'], 'attack' :game_map.player[1].attrs['attack1'], 'health': 100}}
Popoie = {'Name': game_map.player[2].attrs['name'],'Player Level': game_map.player[2].attrs['level'], 'Player Exp': game_map.player[2].attrs['playerxp'], 'Next Level': game_map.player[2].attrs['Nextlvl'], 'player_stats' : {'Strength': game_map.player[2].attrs['strength'], 'Dexterity': game_map.player[2].attrs['dexterity'], 'Endurance': game_map.player[2].attrs['endurance'], 'attack' :game_map.player[2].attrs['attack1'], 'health': 100}}
if room.party[0].attrs['member'] == '0':
party.append(Randi)
print ''
print '*****************************'
print 'Randi has joined your party.'
print '*****************************'
print ''
for member in room.party:
room.party.remove(member)
elif room.party[0].attrs['member'] == '2':
party.append(Purim)
print ''
print '*****************************'
print 'Purim has joined your party.'
print '*****************************'
print ''
for member in room.party:
room.party.remove(member)
elif room.party[0].attrs['member'] == '1':
party.append(Popoie)
print ''
print '*****************************'
print 'Popoie has joined your party.'
print '*****************************'
print ''
for member in room.party:
room.party.remove(member)
else:
pass
def overworld_music(room):
pygame.mixer.init()
pygame.init()
sound = pygame.mixer.Sound('Into_the_Thick_of_it_Secret_of_Mana_Music.wav')
sound.set_volume(.10)
sound.play()
def intro():
global game_map
intro_text = game_map.intro[0].text[0].value
things = intro_text.split('.')
for words in things:
print words
time.sleep(2.25)
time.sleep(8)
pygame.mixer.fadeout(2000)
def battle_system(room, monsters):
global player_inventory
global sword_count
global wallet
monster = room.monster[0]
monster_name = monster.attrs["name"]
monster_damage = int(room.monster[0].attrs['damage'])
monster_health = room.monster[0].attrs["health"]
experience = room.monster[0].attrs['exp']
battle_music(0, room)
score = int(room.monster[0].attrs['score'])
for character in party:
if len(party) == 1:
character1 = party[0]
if len(party) == 2:
character1 = party[0]
character2 = party[1]
if len(party) == 3:
character1 = party[0]
character2 = party[1]
character3 = party[2]
else:
pass
for character in party:
character["player_stats"]['attack'] = int(character["player_stats"]['attack'])
print 'You have encountered a ', monster_name
while character['player_stats']['health'] and monster_health >0:
if "Rusty Sword" in player_inventory:
if sword_count == 1:
character["player_stats"]['attack'] = (character["player_stats"]['attack'] + 18)
sword_count = sword_count + 1
if "Mana Sword" in player_inventory:
character["player_stats"]['attack'] = 1100
for character in party:
print character['Name'], character['player_stats']['health']
print 'Enemy Health', monster_health
print character['Name'] , 'is up to fight'
command = raw_input('What would you like to do>>>')
verb, noun = parse_command(command)
attack_number = 0
for character in party:
if verb == "attack":
monster_health = damage(character, int(monster_health))
print 'You attack the ', monster_name
if monster_health >= 0:
character['player_stats']['Dexterity'] = int(character['player_stats']['Dexterity'])
dodge_chance = random.randint( 0, (100 / character['player_stats']['Dexterity']))
if dodge_chance == 25:
print monster_name, 'misses you'
else:
if attack_number == 0:
if len(party) == 1:
character1['player_stats']['health'] = character1['player_stats']['health'] - monster_damage
attack_number = attack_number + 1
if len(party) == 2:
choice = random.randint(1,2)
if choice == 1:
character1['player_stats']['health'] = character1['player_stats']['health'] - monster_damage
attack_number = attack_number + 1
if choice ==2:
character2['player_stats']['health'] = character2['player_stats']['health'] - monster_damage
attack_number = attack_number + 1
if len(party) == 3:
choice = random.randint(1,3)
if choice == 1:
character1['player_stats']['health'] = character1['player_stats']['health'] - monster_damage
attack_number = attack_number + 1
if choice == 1:
character2['player_stats']['health'] = character2['player_stats']['health'] - monster_damage
attack_number = attack_number + 1
if choice == 1:
character3['player_stats']['health'] = character3['player_stats']['health'] - monster_damage
attack_number = attack_number + 1
else:
pass
elif verb == 'run':
print 'Cannot escape'
elif verb in ['use', 'Use']:
if noun == 'Candy' and 'Candy' in player_inventory:
candy_system(room, noun)
else:
print "You cannot use that item"
else:
print 'What are you thinking?!?'
print monster_name, "attacks you for ", monster_damage, "while you are fumbling around."
character['player_stats']['health'] = character['player_stats']['health'] - monster_damage
if character['player_stats']['health'] <=0:
print 'You have been eaten by a ', monster_name
print "Game Over"
raw_input('...')
break
if monster_health <= 0:
print 'You have beaten a', monster_name
print ''
print 'You have', character['player_stats']['health'], 'health remaining'
print ''
experience_system(int(experience))
gold = room.monster[0].attrs['gold']
wallet_system(gold)
battle_music(69, room)
score_system(room, score)
# end_the_game(room)
if room.monster[0].attrs['boss'] == 'True':
room.monster.remove(monster)
else:
pass
return
def experience_system(gained_exp):
global party
base_health = 100
print "You gained,", gained_exp, "experience."
nstr, ndex, nint = 0, 0, 0
for characters in party:
characters["Player Exp"] = int(characters["Player Exp"]) + gained_exp
characters["Next Level"] = int(characters["Next Level"])
while characters['Player Exp'] >= characters['Next Level']:
print 'Character Name:',characters["Name"]
characters["Player Level"] = int(characters["Player Level"]) + 1
characters["Player Exp"] = characters["Player Exp"] - characters["Next Level"]
characters["Next Level"] = round(characters["Next Level"] * 1.5)
nstr = random.randint(1 , 5)
ndex = random.randint(1 , 5)
nint = random.randint(1 , 20)
#Prints stat gain
characters['player_stats']['Strength'] = int(characters['player_stats']['Strength']) + nstr
characters['player_stats']['Dexterity'] = int(characters['player_stats']['Dexterity']) + ndex
characters['player_stats']['Endurance'] = int(characters['player_stats']['Endurance']) +nint
characters['player_stats']['attack'] = int(characters['player_stats']['attack'])
characters['player_stats']['attack'] = (characters['player_stats']['attack'] + (characters['player_stats']['Strength']))
characters["player_stats"]['health'] = base_health + (characters['player_stats']['Endurance'] * 2)
print "Player Level:", characters["Player Level"]
print 'Experience Needed To Next Level:', int(characters['Next Level']) - int(characters["Player Exp"])
print 'Strength Gain:', nstr
print "Dexterity Gain:", ndex
print "Endurance Gain:", nint
print "Characters New Max Health:", characters["player_stats"]['health']
print ''
def inn_system(room):
global wallet
base_health = 100
print "It cost ten gold to stay at the inn, would you like to stay?"
choice = raw_input('>')
if choice in ["yeah", "Yes", "yes", "Yeah", "Y"]:
if wallet >= 10:
pygame.mixer.init()
pygame.init()
sound = pygame.mixer.Sound('Close_Your_Eyelids_Secret_of_Mana_Music.wav')
sound.play()
wallet = wallet - 10
for character in party:
character['player_stats']['health'] = character["player_stats"]['health'] = base_health + (character['player_stats']['Endurance'] * 2)
print 'You stay at the inn and feel well rested.'
print 'Hp fully recovered.'
save_game(room)
time.sleep(5)
pygame.mixer.fadeout(2000)
return room
else:
print 'You do not have enough money'
return room
else:
return room
def score_system(room, enemy_score):
global score
score = score + enemy_score
print 'Score:', score
def save_game(room):
print 'Would you like to save your game?'
choice = raw_input('>>>')
if choice in ['yes', 'Yes', 'yeah', 'Yeah', 'y', 'Y']:
room_idx = game_map.building.index(room)
player.attrs["room"] = str(room_idx)
save_file = raw_input("enter a name for the save file>")
game_data = game_map.flatten_self()
with open("saved_games\\" + save_file + ".xml", "w") as f:
f.write(game_data)
print "game saved!"
return room
else:
pass
return room
def wallet_system(gold):
global wallet
wallet = int(wallet) + int(gold)
def damage(attacker, defender):
attacker['player_stats']['attack'] = int(attacker['player_stats']['attack'])
if random.randint(0, 100) > 95:
damage = random.randint(attacker['player_stats']['attack']-5, attacker['player_stats']['attack'] + 15)
print 'You scored a critical hit'
else:
damage = random.randint(attacker['player_stats']['attack'], attacker['player_stats']['attack']) * 1.1
print 'You have done', damage, 'damage'
defender = defender - damage
return defender
def describe(room):
print room.text[0].value
if room.item:
print '***************Items***************'
item_text = "You see"
for item in room.item:
item_text += " a " + item.attrs["name"]
print item_text
if room.exit:
print '***************Exits***************'
for exit in room.exit:
room_text = 'You see the '
room_text += exit.attrs["name"] + ' to your ' + exit.attrs["dir"]
print room_text
print '***********************************'
def town_text(room):
words = room.town_text[0].value
things = words.split('.')
for word in things:
print word
time.sleep(5)
room.town_text.remove(room.town_text[0])
def parse_command(command):
words = command.split()
if len(words) < 1:
words = ["BAD_COMMAND"]
verb = words[0]
noun = " ".join(words[1:])
return verb, noun
def candy_system(room, noun):
global character
global player_inventory
base_health = 100
if noun in player_inventory:
if noun == 'Candy':
character['player_stats']['health'] = character["player_stats"]['health'] = base_health + (character['player_stats']['Endurance'] * 2)
print 'Hp Restored To:', character['player_stats']['health']
player_inventory.remove('Candy')
if noun == 'Health Boost':
character['player_stats']['Endurance'] = character['player_stats']['Endurance'] + 5
player_inventory.remove('Health Boost')
if noun == 'Strength Boost':
character['player_stats']['Strength'] = character['player_stats']['Strength'] + 5
player_inventory.remove('Strength Boost')
if noun == 'Agility Boost':
character['player_stats']['Dexterity'] = character['player_stats']['Dexterity'] + 5
player_inventory.remove('Agility Boost')
print character
def store_system():
global wallet
global player_inventory
print 'You have', wallet, 'gold'
print 'This is what we have in stock:'
print '1. Candy'
print 'Cost: 10 Gold'
print '****************'
print '2. Health Boost'
print 'Cost: 500 Gold'
print '****************'
print '3. Strength Boost'
print 'Cost: 500 Gold'
print '****************'
print '4. Agility Boost'
print 'Cost: 500 Gold'
choice = raw_input('>>>')
if choice in ['1', 'candy', 'Candy']:
if wallet >= 10:
player_inventory.append('Candy')
wallet = wallet - 10
else:
print 'Sorry, you do not have enough gold.'
if choice in ['2', 'health boost', 'health Boost', 'Health boost', 'Health', 'Health Boost', 'health']:
if wallet >= 10:
player.inventory.append('Health Boost')
wallet = wallet - 500
else:
print 'Sorry, you do not have enough gold.'
if choice in ['3', 'Strength Boost', 'Strength boost', 'strength Boost', 'Strength', 'strength']:
if wallet >= 10:
player_inventory.append('Strength Boost')
wallet = wallet - 500
else:
print 'Sorry, you do not have enough gold.'
if choice in ['4', 'Agility Boost', 'Agility boost', 'agility Boost', 'Agility', 'agility']:
if wallet >= 10:
player_inventory.append('Agility Boost')
wallet = wallet - 500
else:
print 'Sorry, you do not have enough gold.'
def end_the_game(room):
if room.monster[0].attrs['endcode']:
if room.monster[0].attrs['endcode'] == '1':
print 'The game is over!!!'
else:
pass
def run_command(room, verb, noun):
global player
global player_inventory
global wallet
global party
exits, items, locked, reqs, monsters = get_room_data(room)
#hopefully one day will check to see if doors are locked, and if so, let me pass through them if I have the key.
if room.town_text:
town_text(room)
describe(room)
if monsters:
battle_system(room, monsters)
if room.party:
party_builder(room)
if verb in ["go", "g", "walk", "run", "sprint", "w", "r", "s"]:
room_exit = exits.get(noun, None)
if room_exit:
lock = locked.get(room_exit.attrs["name"])
if lock == 'True':
req = reqs[room_exit.attrs["name"]]
if req == "None" or req in player_inventory:
# print 'You unlocked the', room_exit.attrs["name"]
return rooms_by_name[room_exit.attrs["link"]]
else:
print room_exit.attrs["name"], 'is blocked, you cannot pass.'
return room
else:
print 'You pass through the', room_exit.attrs["name"]
return rooms_by_name[room_exit.attrs["link"]]
else:
print "You can't go there."
return room
#look to see if there are items in the room, and add them to inventory
elif verb in ["look", "Look", "LOOK", "inspect", "Inspect", "INSPCET"]:
if noun:
if noun in items:
item = items[noun]
print item.value
elif noun in exits:
exit = exits[noun]
print exit.attrs.get("name", "you see nothing")
else:
print "you see nothing"
else:
describe(room)
return room
elif verb in ["take", "get", 'grab', 'Take', 'Get', 'Grab', 'obtain', 'Obtain'] :
if noun in items:
for name, item in items.iteritems():
print "You have taken the" , name
player_inventory.append(name)
room.item.remove(item)
return room
else:
return room
elif verb == "save":
room_idx = game_map.building.index(room)
player.attrs["room"] = str(room_idx)
save_file = raw_input("enter a name for the save file>")
game_data = game_map.flatten_self()
with open("saved_games\\" + save_file + ".xml", "w") as f:
f.write(game_data)
print "game saved!"
return room
elif verb == "quit":
print 'Sorry to see you go, goodbye'
sys.exit()
elif verb in ["stay", "Stay", "Sleep", "sleep"]:
print room.room_name[0].value
if room.room_name[0].value in ['Potos Inn', 'Pandora Inn', 'Dwarf Village Inn', 'Kakkara Inn', 'Mandala Inn','Gold Island Inn']:
inn_system(room)
return room
elif verb in ["shop", "Shop", "Buy", "buy"]:
if room.room_name[0].value in ['Potos Inn', 'Pandora Inn', 'Dwarf Village Inn', 'Kakkara Inn', 'Mandala Inn','Gold Island Inn']:
store_system()
return room
elif verb == "stats" or verb == "Stats":
for character in party:
print character['Name']
print "You have", wallet, "gold"
return room
#brief help guide
elif verb in ["help", "Help", "HELP", "HElp"]:
print "The game is fairly simple to play."
print "Commands generally break down to: look, go, or, take"
print "Also, if you would like to view your inventory, enter a capital 'I'"
print 'Try sleeping in or staying in inns'
return room
elif verb in ['use', 'Use']:
candy_system(room, noun)
return room
elif verb in ["i", "I", "inv", "INV", "inventory"]:
print "Your inventory contains: "
print ", ".join(player_inventory)
return room
else:
print "unrecognized command"
return room
def get_room_data(room):
exits = dict()
for room_exit in room.exit:
exits[room_exit.attrs["name"]] = room_exit
exits[room_exit.attrs["dir"]] = room_exit
monster_dict = dict()
for monster in room.monster:
monster_dict[monster.attrs['name']] = monster
items = dict()
for item in room.item:
items[item.attrs["name"]] = item
pre_req_dict=dict()
for room_exit in room.exit:
pre_req_dict[room_exit.attrs["name"]] = room_exit.attrs["req"]
locked = dict()
for room_exit in room.exit:
locked[room_exit.attrs["name"]] = room_exit.attrs["locked"]
return exits, items , locked, pre_req_dict, monster_dict
if __name__ =="__main__":
try:
main()
except:
exception_string = traceback.format_exc()
logger.write_line([exception_string])
print exception_string