-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
140 lines (117 loc) · 4.11 KB
/
actions.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
#!/bin/python2
#
#~actions.py~
from time import sleep
from superRandom import *
import os
import monsters
import pickle
def roll_dice(Player):
#TODO: add more rolls since some options come up too often
#If zork-style gameplay is enabled, this will no longer be a problem
roll = superRandrange(1,6)
Player.steps += roll
Player.turns += 1
if Player.turns > 6:
Player.turns = 0
#mid-game boss
if Player.steps >= 100 and Player.dragon_attack is False:
dragon = monsters.CreateMonster(200,25,"Dragon") #HP,damage_dealt,name
dragon.boss_attack(Player)
Player.dragon_attack = True
return
#final boss
elif Player.steps >= 150:
basilisk = monsters.CreateMonster(300,40,"Basilisk") #HP,damage_dealt,name
basilisk.boss_attack(Player)
Player.basilisk_attack = True
return
print "\nYou walked %d paces and..." % roll
sleep(1)
clearscreen()
if roll == 1:
Player.find_gold()
elif roll == 2:
print "\nYou stepped on a booby trap!"
Player.take_damage(superRandint(1,7))
elif roll == 3:
print "\nYou found a locked door..."
if Player.has_key is True:
print "\nYou opened it with the key that you found"
Player.find_weapon()
Player.has_key = False
else:
print "\nBut you can't open it since you don't have the key"
sleep(2)
elif roll == 4:
print "\nYou stumbled upon a dead body, you look through it's backpack...."
sleep(1)
number = superRandint(0,3)
if number == 1:
Player.find_gold()
elif number == 2:
Player.find_potions()
elif number == 3:
print "\nYou found a key, wonder what it opens..."
Player.has_key = True
sleep(2)
else:
print "\nYou didn't find anything...looks like someone else already got to it"
sleep(2)
elif roll == 5:
monster_names = ["Gremlin", "Demon", "Zombie"]
choice = superChoice(monster_names)
if choice == "Gremlin":
newMonster = monsters.CreateMonster(superRandint(10,15), superRandint(1,7),"Gremlin") #HP,damage_dealt,name
newMonster.attack(Player)
del newMonster
elif choice == "Demon":
newMonster = monsters.CreateMonster(superRandint(15,25), superRandint(7,15),"Demon") #HP,damage_dealt,name
newMonster.attack(Player)
del newMonster
else:
newMonster = monsters.CreateMonster(superRandint(25,35), superRandint(10,20),"Zombie") #HP,damage_dealt,name
newMonster.attack(Player)
del newMonster
else:
print ("\nYou're safe for the moment!\n"
"\nTake a minute to catch your breath")
if Player.health <= 60 and Player.potions > 0:
Player.low_health()
sleep(2)
def visit_shop(Player):
clearscreen()
print ("\nWhat would you like to purchase?\n"
"You currently have %d gold coins.\n"
"\nP) Health Potions\n""W) Weapons\n"
"N) Nothing/Leave Store" %(Player.gold))
choice = raw_input("\nChoice: ").lower()
clearscreen()
if choice == 'p':
Player.buy_potions()
elif choice == 'w':
Player.buy_weapon()
elif choice == 'n':
print "\nThanks for stopping by!"
sleep(2)
return
else:
print "\nNot a valid choice"
sleep(2)
visit_shop(Player)
def quit_game():
print "\nGood Bye!\n"
return 0
def save_game(Player):
with open("savegame.pkl",'wb') as output:
pickle.dump(Player,output,pickle.HIGHEST_PROTOCOL)
print "\nGame saved!"
sleep(1)
def load_game(): #TODO: fix me!
with open('savegame.pkl','rb') as input:
Player = pickle.load(input)
print "\nSaved game has been loaded!"
sleep(2)
return Player
def clearscreen():
os.system('cls' if os.name == 'nt' else 'clear')