-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
354 lines (337 loc) · 14.2 KB
/
Copy pathgame.py
File metadata and controls
354 lines (337 loc) · 14.2 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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import location, player, random, time, os, boss
import item as items
from datetime import datetime
# Confirm commit
seed = input("Enter a seed: ")
tile = location.Location(seed + "0,0")
user = player.Player(input("What is your name: "))
keyFindx = random.randint(-25, 25)
keyFindy = random.randint(-25, 25)
gateFindx = random.randint(-25, 25)
gateFindy = random.randint(-25, 25)
gateMapx = random.randint(gateFindx - 1, gateFindx + 1)
gateMapy = random.randint(gateFindy - 1, gateFindy + 1)
keyMapx = random.randint(keyFindx - 1, keyFindx + 1)
keyMapy = random.randint(keyFindy - 1, keyFindy + 1)
key = "{},{}".format(gateFindx, gateFindy)
x = 0
y = 0
tiles = {}
searched_tiles = []
hasTele = False
# print("{}, {}".format(gateFindx, gateFindy))
# For debug perposes
def move(direction):
global x, y
if direction == "n":
y += 1
elif direction == "e":
x += 1
elif direction == "s":
y -= 1
elif direction == "w":
x -= 1
key = "{},{}".format(x, y)
if key in tiles:
return tiles[key]
else:
newtile = location.Location(seed + key)
if x == gateFindx and y == gateFindy:
newtile.name = "The Gate"
if x == gateMapx and y == gateMapy:
newtile.name = "The Platform"
tiles[key] = newtile
return newtile
def bossBattle():
commandRun = False
os.system('cls')
bossFight = boss.getBoss()
print("As you open the gates, you see a heavily armoured enemy emerge from them...")
time.sleep(3)
while bossFight.isAlive() and user.isAlive():
print("You have {} health! Enemy has {} health!".format(user.health, bossFight.health))
command = input("FIGHT MODE > ")
if command == "punch":
commandRun = True
if random.randint(1, 10) < 10:
print("You punched the enemy!")
bossFight.health -= 1
else:
print("You are clumsy and missed the punch!")
elif command == "curb stomp":
commandRun = True
if random.randint(1, 5) == 1:
print("Wow! a hit!")
bossFight.health -= 5
else:
print("What a horrible attempt!")
elif command == "items":
if user.inventory:
print("You have: {}".format(user.getItems()))
else:
print("You have no items")
elif command.startswith("use"):
if command == "use" or command == "use ":
print("You must specify what item to use")
else:
_, item = command.split(" ", 1)
if user.hasItem(item):
if items.getType(item) == "Weapon" or items.getType(item) == "Healing/Weapon":
commandRun = True
print("Used {}".format(item))
bossFight.health -= user.useWeapon(item)
if user.getUses(item) == 3:
user.removeItem(item)
print("Your {} broke".format(item))
if items.getType(item) == "Healing/Weapon":
user.removeItem(item)
print("You used your {} to attack".format(item))
else:
print("Can't use {} to fight".format(item))
else:
print("You don't have a {}!".format(item))
if bossFight.health > 0 and commandRun:
user.health -= bossFight.damage
if random.randint(1, 3) == 1:
user.destroyItem()
commandRun = False
else:
global running
running = False
def debugMode(tile):
global x, y, debugOn
print("You have entered debug mode!")
debugOn = True
while debugOn:
print("Location: {}, on grid location {}, {}".format(tile.name, x, y))
cmd = input("$ > ")
if cmd.lower() == "changex":
amountChange = input("New x: ")
x = int(amountChange)
tile = move("debug")
elif cmd.lower() == "changey":
amountChange = input("New y: ")
y = int(amountChange)
tile = move("debug")
elif cmd.lower() == "exit":
debugOn = False
elif cmd.lower().startswith("additem"):
_, item1 = cmd.split(" ", 1)
if items.doesExist(item1):
user.addItem(items.addItem(item1))
print("Added item: {}".format(item1))
else:
print("That item does not exist!")
elif cmd.lower().startswith("addspecialitem"):
_, item2 = cmd.split(" ", 1)
if items.doesSpecialExist(item2):
user.addItem(items.getSpecialItem(item2))
print("Added item: {}".format(item2))
else:
print("That item does not exist!")
elif cmd.lower().startswith("addpergameitem"):
_, item3 = cmd.split(" ", 1)
if items.doesPerGameExist(item3):
user.addItem(items.getPerGameItem(item3))
print("Added item: {}".format(item3))
else:
print("That item does not exist!")
elif cmd.lower() == "keylocation":
print("Key Location: {}, {}".format(keyFindx, keyFindy))
elif cmd.lower() == "gatelocation":
print("Gate Location: {}, {}".format(gateFindx, gateFindy))
elif cmd.lower() == "sethealth":
setHealth = input("New health: ")
user.health = int(setHealth)
elif cmd.lower() == "instaboss":
bossBattle()
else:
print("That is not a command")
running = True
while running and user.isAlive():
if tile.name == "The Gate":
print("You have come across a massive gate, leading to an unknown place")
elif tile.name == "The Platform":
print("Mysterious Platform")
else:
print("You are in {}".format(tile.name))
if tile.enemy and tile.enemy.isAlive():
print("There is an enemy here! They have {} health".format(tile.enemy.health))
command = input("> ")
if command.lower() == "items":
if user.inventory:
print("You have: {}".format(user.getItems()))
else:
print("You have no items")
elif command.lower() == "move":
if tile.enemy and tile.enemy.isAlive():
print("You cannot move. There are enemies nearby")
else:
direction = input("N/E/S/W > ")
if direction == "":
print("You must give a direction")
elif direction[0].lower() == "n":
print("Go North")
tile = move("n")
elif direction[0].lower() == "e":
print("Go East")
tile = move("e")
elif direction[0].lower() == "s":
print("Go South")
tile = move("s")
elif direction[0].lower() == "w":
print("Go West")
tile = move("w")
else:
print("Moving Cancelled")
elif command.lower().startswith("move"):
if tile.enemy and tile.enemy.isAlive():
print("You cannot move. There are enemies nearby")
elif command.lower() == "move ":
print("You must give a direction")
else:
_, direction = command.split(" ", 1)
if direction[0].lower() == "n":
print("Go North")
tile = move("n")
elif direction[0].lower() == "e":
print("Go East")
tile = move("e")
elif direction[0].lower() == "s":
print("Go South")
tile = move("s")
elif direction[0].lower() == "w":
print("Go West")
tile = move("w")
else:
print("That's not a direction")
elif command.lower() == "debug":
debugMode(tile)
tile = move("debug")
elif command.lower() == "search":
if tile.seed in searched_tiles:
print("You have already searched here")
continue
random.seed(seed + str(x) + str(y))
if x == keyFindx and y == keyFindy:
print("You have discovered an old Gate Key!")
user.addItem(items.addItem("Gate Key"))
elif random.randint(1, 5) == 1:
print("You seem to have found something")
user.addItem(items.getRandomItem())
else:
print("You search for a while, but find nothing")
searched_tiles.append(tile.seed)
elif command.lower() == "fight":
random.seed(datetime.now())
while tile.enemy.isAlive() and user.isAlive():
print("You have {} health! Enemy has {} health!".format(user.health, tile.enemy.health))
commandRun = False
command = input("FIGHT MODE > ")
if command.lower() == "punch":
if random.randint(1, 10) < 10:
print("You punched the enemy!")
tile.enemy.health -= 1
commandRun = True
else:
print("You are clumsy and missed the punch!")
commandRun = True
elif command.lower() == "curb stomp":
if random.randint(1, 5) == 1:
print("Wow! a hit!")
tile.enemy.health -= 5
commandRun = True
else:
print("What a horrible attempt!")
commandRun = True
elif command.lower() == "items":
if user.inventory:
print("You have: {}".format(user.getItems()))
else:
print("You have no items")
elif command.lower().startswith("use"):
if command.lower() == "use" or command.lower() == "use ":
print("You must specify what item to use")
else:
_, item = command.split(" ", 1)
if user.hasItem(item):
if items.getType(item) == "Weapon" or items.getType(item) == "Healing/Weapon":
print("Used {}".format(item))
tile.enemy.health -= user.useWeapon(item)
commandRun = True
if user.getUses(item) == 3:
user.removeItem(item)
print("Your {} broke".format(item))
if items.getType(item) == "Healing/Weapon":
user.removeItem(item)
print("You used your {} to attack".format(item))
else:
print("Can't use a {} to fight".format(item))
else:
print("You don't have a {}!".format(item))
if tile.enemy.health > 0 and commandRun:
user.health -= tile.enemy.damage
elif tile.enemy.health <= 0:
if random.randint(1, 5) == 1:
itemRecieved = items.getRandomItem()
user.addItem(itemRecieved)
print("You killed the enemy and they dropped a {}!".format(itemRecieved.name))
if hasTele == False:
print("They also dropped a strange tablet-like object")
user.addItem(items.addItem("Teleporter"))
hasTele = True
else:
print("You killed the enemy!")
elif command.lower() == "help":
print("Command options:")
print("items, move, search, fight, use")
elif command.lower().startswith("use"):
if command.lower() == "use" or command.lower() == "use ":
print("You must specify what item to use")
else:
_, item = command.split(" ", 1)
if user.hasItem(item):
if items.getType(item) == "Utility":
if items.getName(item) == "Teleporter":
print("Are you sure you want to use this? This is a one use item and cannot be rediscovered")
isSure = input("YES/NO > ").lower()
if isSure == "yes":
print("You used the teleporter")
x = gateMapx
y = gateMapy
tile = move("tele")
user.removeItem("Teleporter")
elif isSure == "no":
print("You decided not to use the teleporter")
else:
print("That's not an option")
elif items.getType(item) == "Info":
if items.getName(item) == "Map":
print("You look at your map and determine you are around the coordinates {}, {}".format(x, y))
elif items.getName(item) == "Gate Map":
print("You look at the Gate Map and discover a red circle around the general area of {}, {}".format(gateMapx, gateMapy))
elif items.getName(item) == "Key Map":
print("You look at the Key Map and discover a red circle around the general area of {}, {}".format(keyMapx, keyMapy))
elif items.isSpecialItem(item) and tile.name != "The Gate":
print("This is a special item! You cannot use it here")
elif items.isSpecialItem(item) and tile.name == "The Gate":
bossBattle()
elif items.getType(item) == "Weapon":
print("This is a fighting item. you cannot use that right now")
else:
print("You have used {}".format(item))
user.use(item)
user.removeItem(item)
else:
print("You don't have {}".format(item))
elif command == "":
print("You must give a command")
os.system('cls')
if user.isAlive():
print("You did it! You have won!")
print("")
input("Press enter to end game")
else:
print("Game Over!")
print("")
input("Press enter to end game")