-
Notifications
You must be signed in to change notification settings - Fork 7
/
J) The Slumber of the Doom King.py
189 lines (144 loc) · 6.7 KB
/
J) The Slumber of the Doom King.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
import random
import time
# Stats
health=100
gold=0
alive=True
encounter1=False # This is used so that unique encounter only happen once.
# function that provides input from player
def input_direction():
direction = input("Which direction do you want to go? ")
direction=direction.lower()
while direction not in ["north", "south", "east", "west", "exit"]:
direction = input("Invalid answer,which direction do you want to go? ")
direction=direction.lower()
return direction # When you execute input_direction it will return 'the direction' eg: north,south,east,west
# Return statement is used in a function to return something to the caller program.
def nothing():
pass
def jester():
global encounter1 # If you do not use global the encounter within the function is consider a local variable
# and you will have a "local variable referenced before assignment error"
while encounter1==False:
print ("You see a sad jester in the corner of the room")
print ("He ask you a question")
question1=input("Can you spare me some life for some gold ? Y or N " )
question=question1.lower()
if question=="y" or question=="yes":
global health
global gold
health=-5
gold=+300
print("The Jester smile and say 'thank you'.")
print("You lose 5 life ")
print("You gain 300 gold")
encounter1=True
else:
print("The Jester scream at you 'go away!' ")
encounter1=True
else:
pass
print (" The Slumber of the Doom King ")
print(" ")
print("Goal: Steal as much gold as possible and escape the castle of the Doom King before he consume your soul !!")
print("Direction: North/East/South/West/Quit")
time.sleep(1.5)
# Set up the Locations
compass = { "north" : {1:-1,2:-1,3:-1,4:-1,5:1,6:2,7:3,8:4,9:5,10:6,11:7},
"east": {1:2,2:3,3:4,4:-1,5:6,6:7,7:8,8:-1,9:10,10:11,11:12},
"south": {1:5,2:6,3:7,4:8,5:9,6:10,7:11,8:12,9:-1,10:-1,11:-1},
"west": {1:-1,2:1,3:2,4:3,5:-1,6:5,7:6,8:7,9:-1,10:9,11:10}
}
descr = {
1: "Location: Master bedroom. You feel something is watching you",
2: "Location: Nursery. There is a sense of forelorn here",
3: "Location: Treasury. It has been ransacked a long time ago",
4: "Location: Library. It is filled with books of black magic ",
5: "Location: Dining room. Someone has been here recently",
6: "Location: Torture chamber. You feel sick with dread...",
7: "Location: Garden. All flowers has withered and died ",
8: "Location: Burial Chamber. Something should be forgotten",
9: "Location: Armoury. Filled with a assortment of demonic weapons",
10: "Location: Kitchen. Old pots and pans clutters the room ",
11: "Location: Servant Quarter. A skeleton lies on the floor, a sad sight",
12: ""}
# Unique events ( You can add different types of quests/storylines/characters for each location
events = {
1: nothing,
2: jester,
3: nothing,
4: nothing,
5: nothing,
6: nothing,
7: nothing,
8: nothing,
9: nothing,
10: nothing,
11: nothing,
12: nothing,}
currentRoom = 1
# Game loop
while alive==True:
# Describe the current room
print (descr[currentRoom])
events[currentRoom]()
loot=random.randrange(1,20)
loot1=str(loot)
print ("you find",loot1,"gold")
gold+=loot
print ("Total gold:",gold)
print("Life:",health)
# See if you awake the Doom King or not
sleep=random.randint(1,9)
if sleep ==5 and currentRoom !=12:
damage=random.randrange(30,60)
health-=damage
print("The Doom King is awake, he attacks you !!")
print("Life:", health)
if health <=0:
print("The Doom King consume your soul and break your body.( THE END )")
input("Press enter to escape")
break
else:
print("Thankfully you escape and the King falls back into slumber")
elif sleep==1 or sleep==2:
print("You hear the Doom King groan but then silence")
elif sleep==3 or sleep==4:
print("The Doom King is left undisturbed")
elif sleep==6 or sleep==7:
print("The Doom King remains asleep")
else:
print( "The Doom King slumber..")
newDir = input_direction() # calling the function of user input, works because the 'return' function was used
if newDir == "quit": # If you wish to exit
print ("Good bye")
break
else:
# Otherwise look up whether there is a path that way
if compass[newDir][currentRoom] != -1: # ( if the nested value is a -1 means there is no path )
currentRoom = compass[newDir][currentRoom] # eg: compass[east][1] which is dic[key][nested key] will return value 2 which will be the new room/key
print(newDir) # This is just to demonstrate how 'return' works, can delete if you want
else:
print ("There is no path in that direction")
# If you find the exit
if currentRoom ==12:
print("Location: Exit Gate. You have found the exit, well done !!")
print("Total gold:",gold," can you do better next time?")
input("Press enter to escape")
break
#so the world is set up like
# 1 2 3 4
# 5 6 7 8
# 9 10 11 12
#You begin at 1 since currentRoom = 1 If you go east you will go to 2 because
#compass[newDir][currentRoom] equals to compass[east][1] which will
#extract the key of 2 because ('east": {1:2,')and then the new currentRoom becomes 2
# if compass[newDir][currentRoom] != -1: ( if the nested value is a -1 means there is no path )
# currentRoom = compass[newDir][currentRoom]
# If you then go south then it will be compass[south][2] which will obtain
# the key 6 because ("south": {1:5,2:6,) and then the new currentRoom becomes 6
# You have then travelled from A to C on the map
# A B x x
# x C x x
# x x x x
#https://github.com/Ninedeadeyes/15-mini-python-games-