generated from Code-Institute-Org/python-essentials-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
460 lines (396 loc) · 20.8 KB
/
run.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
import os
import sys
from random import randint
import entity
import level
CHECK_POS = 'walk'
GONE_ROGUE_LOGO = """
▄████ ▒█████ ███▄ █ ▓█████ ██▀███ ▒█████ ▄████ █ ██ ▓█████
██▒ ▀█▒▒██▒ ██▒ ██ ▀█ █ ▓█ ▀ ▓██ ▒ ██▒▒██▒ ██▒ ██▒ ▀█▒ ██ ▓██▒▓█ ▀
▒██░▄▄▄░▒██░ ██▒▓██ ▀█ ██▒▒███ ▓██ ░▄█ ▒▒██░ ██▒▒██░▄▄▄░▓██ ▒██░▒███
░▓█ ██▓▒██ ██░▓██▒ ▐▌██▒▒▓█ ▄ ▒██▀▀█▄ ▒██ ██░░▓█ ██▓▓▓█ ░██░▒▓█ ▄
░▒▓███▀▒░ ████▓▒░▒██░ ▓██░░▒████▒ ░██▓ ▒██▒░ ████▓▒░░▒▓███▀▒▒▒█████▓ ░▒████
░▒ ▒ ░ ▒░▒░▒░ ░ ▒░ ▒ ▒ ░░ ▒░ ░ ░ ▒▓ ░▒▓░░ ▒░▒░▒░ ░▒ ▒ ░▒▓▒ ▒ ▒ ░░ ▒░
░ ░ ░ ▒ ▒░ ░ ░░ ░ ▒░ ░ ░ ░ ░▒ ░ ▒░ ░ ▒ ▒░ ░ ░ ░░▒░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░░ ░ ░ ░ ░ ▒ ░ ░ ░ ░░░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░"""
ent_dict = {'runt': ['runt', 5, 3], 'bruiser': ['bruiser', 10, 5],
'boss': ['boss', 20, 7], 'lunch': ['lunch', 0, 5],
'stimulant': ['stimulant', -2, 2], 'vigour': ['vigour', 0, 3]}
ent_names = list(ent_dict.keys())
l1 = [ent_dict['runt'], ent_dict[ent_names[randint(3, 5)]]]
l2 = [ent_dict['bruiser'], ent_dict[ent_names[randint(3, 5)]]]
l3 = [ent_dict['boss'], ent_dict[ent_names[randint(3, 5)]]]
enemy, loot, stairs = entity.ents_init(l1[0], l1[1])
def menu():
"""
Handles UI for the title screen of Gone Rogue
ARGS: strings - 'i', 'h', 's'
RETURNS: - introduction to the game and its historical context
or - instructions describing how to interact with the game
or - starts the game loop"""
# clears game screen
os.system('cls' if os.name == 'nt' else 'clear')
# prints title
print(GONE_ROGUE_LOGO)
print("Welcome to Gone Rogue")
# creates menu loop
while True:
menu_choice = input('\ni = intro, h = how to play, s = start\n')
# on user input 'i' prints introduction
if menu_choice == 'i':
# print statements with values of ("\033[A \033[A")
# remove the line above
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A\n")
print("""
The year is 1980. Miami is burning, Post-Its just hit the shelves,
the MGM is on fire and somebody just shot John Lennon.
PRESS ENTER""")
# empty input to allow user to cue the next line when they're ready
input()
print("\033[A \033[A")
print("\033[A \033[A")
print("""
The world is chaotic and unpredictable.
Will there be peace? Will there be justice? Will there be revolution?
""")
input()
print("\033[A \033[A")
print("\033[A \033[A")
print("""
Enter procedural generation,
a way of producing 'randomised' worlds from stable rules.""")
input()
print("\033[A \033[A")
print("""
This is the world of Rogue, the original Roguelike game
that bore an entire genre dedicated to those seeking to witness
the illusion of control shattering before them.""")
input()
print("\033[A \033[A")
print("""
It gave them something they had never seen before.
The game had agency, a life of its own.""")
input()
print("\033[A \033[A")
print("""
Now, 40 years later, entropy has flaunted its inescapable will
and laid waste to the already waning optimism of the mid 20th Century.""")
input()
print("\033[A \033[A")
print("""\n The only cure?
Surrendering yourself to endless possibility.""")
input()
print("\033[A \033[A")
print("""\n Some can follow their instincts
and get their hands dirty.""")
input()
print("\033[A \033[A")
print("\n Others fall behind trying to reason with the chaos.")
input()
print("\033[A \033[A")
print("\n How will you fare in the bloody world of GONE ROGUE?")
input()
os.system('cls' if os.name == 'nt' else 'clear')
print(GONE_ROGUE_LOGO)
print("Welcome to Gone Rogue")
# prints instructions on how to play the game
elif menu_choice == 'h':
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("""
The world of Gone Rogue is unique every time you play.
Once you enter the game, randomness dictates your experience.
Many parameters of the game like map size,
loot attributes, and spawn positions are randomised.
To navigate through the world you must input a direction and press enter.
w = ^
a = <
s = v
d = >
You'll want to grab any loot available (?) before beginning encounters.
Loot has randomised effects. You could find a nutritious lunch,
or end up making sacrifices for your blood sport.
Enemy (#) encounters are triggered by walking over them.
Once you step into an encounter there's no going back,
in the world of Gone Rogue, it's always a fight to the death.""")
input(' PRESS ENTER...\n')
print(GONE_ROGUE_LOGO)
print("Welcome to Gone Rogue")
# breaks out of menu loop
elif menu_choice == 's':
print("\033[A \033[A")
print('It begins...')
input()
os.system('cls' if os.name == 'nt' else 'clear')
print(GONE_ROGUE_LOGO)
print("Welcome to Gone Rogue")
break
else:
print("Try 'i', 'h' or 's'")
input()
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
def battle():
"""
Handles encounter between hero and enemy
ARGS: object attributes - (hero.h_p, hero.power,
enemy.h_p, enemy.power)
RETURNS: - update's hero objects hp
- prints outcome of battle
"""
enemy.h_p -= hero.power
print('\n')
print(f'{hero.name} hits {enemy.name}. {enemy.name} hp: {enemy.h_p}')
input()
if enemy.h_p <= 0:
print(f'You defeated {enemy.name}!')
else:
hero.h_p -= enemy.power
hero_map_att[0] -= enemy.power
print(f'{enemy.name} hits {hero.name}. {hero.name} hp: {hero.h_p}')
input()
print("\033[A \033[A")
if hero.h_p < 0:
print('Shit...')
input()
os.system('cls' if os.name == 'nt' else 'clear')
print("""
▄████ ▄▄▄ ███▄ ▄███▓▓█████ ▒█████ ██▒ █▓▓█████ ██▀███
██▒ ▀█▒▒████▄ ▓██▒▀█▀ ██▒▓█ ▀ ▒██▒ ██▒▓██░ █▒▓█ ▀ ▓██ ▒ ██▒
▒██░▄▄▄░▒██ ▀█▄ ▓██ ▓██░▒███ ▒██░ ██▒ ▓██ █▒░▒███ ▓██ ░▄█ ▒
░▓█ ██▓░██▄▄▄▄██ ▒██ ▒██ ▒▓█ ▄ ▒██ ██░ ▒██ █░░▒▓█ ▄ ▒██▀▀█▄
░▒▓███▀▒ ▓█ ▓██▒▒██▒ ░██▒░▒████▒ ░ ████▓▒░ ▒▀█░ ░▒████▒░██▓ ▒██▒
░▒ ▒ ▒▒ ▓▒█░░ ▒░ ░ ░░░ ▒░ ░ ░ ▒░▒░▒░ ░ ▐░ ░░ ▒░ ░░ ▒▓ ░▒▓░
░ ░ ▒ ▒▒ ░░ ░ ░ ░ ░ ░ ░ ▒ ▒░ ░ ░░ ░ ░ ░ ░▒ ░ ▒░
░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░░ ░
░ ░ ░ ██▓███ ▄▄▄ ░ ██▓ ░ ▐██▌ ░ ░ ░ ░
▓██░ ██▒▒████▄ ▓██▒ ▐██▌░
▓██░ ██▓▒▒██ ▀█▄ ▒██░ ▐██▌
▒██▄█▓▒ ▒░██▄▄▄▄██ ▒██░ ▓██▒
▒██▒ ░ ░ ▓█ ▓██▒░██████▒ ▒▄▄
▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ▒░▓ ░ ░▀▀▒
░▒ ░ ▒ ▒▒ ░░ ░ ▒ ░ ░ ░
░░ ░ ▒ ░ ░ ░
░ ░ ░ ░ ░""")
input()
print('CLICK RUN to play again.')
sys.exit()
else:
battle()
def play_level(state):
"""
Handles the game loop
ARGS: string - describes the state of the hero's current position
RETURNS: - prints dialogue for each encounter
- updates hero position
- updates hero power
- breaks game loop when stairs encountered
- validates user input"""
while True:
if state == 'walk':
move = input('\nWhich way...?\n')
state, hero_index = level.move_hero(hero_map_att, move,
level_map.map, map_limit)
hero_map_att[3] = hero_index
level.print_map(level_map.map, hero_map_att, enemy.position,
loot.position, stairs.position, GONE_ROGUE_LOGO)
continue
if state == 'loot':
level_map.map[hero_index[0]][hero_index[1]] = hero.icon
loot.position = stairs.position
print(f'\nYou picked up {loot.name}!')
if loot.name == 'lunch':
level_map.map[hero_index[0]][hero_index[1]] = hero.icon
hero.h_p += loot.power
hero_map_att[0] += loot.power
print("It's delicious...")
print(f'You gained {loot.power} hp.')
input()
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
elif loot.name == 'stimulant':
level_map.map[hero_index[0]][hero_index[1]] = hero.icon
hero.power *= loot.power
hero_map_att[1] *= loot.power
hero.h_p += loot.h_p
hero_map_att[0] += loot.h_p
print('''You feel way juiced, man!
So juiced it hurts.''')
print('''Your bloodied fists twitch,
itching to get to work.''')
input()
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
else:
level_map.map[hero_index[0]][hero_index[1]] = hero.icon
hero.power += loot.power
hero_map_att[1] += loot.power
print("Is that ginger and chilli?")
print('WOW that packs a punch!')
input()
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
print("\033[A \033[A")
state = 'walk'
continue
if state == 'fight':
battle()
enemy.position = stairs.position
state = 'walk'
elif state == 'stairs':
level_map.map[hero_index[0]][hero_index[1]] = hero.icon
print('\nGoing down?')
break
elif state == 'oob':
os.system('cls' if os.name == 'nt' else 'clear')
level.print_map(level_map.map, hero_map_att, enemy.position,
loot.position, stairs.position, GONE_ROGUE_LOGO)
print("You walked into a wall.\n")
move = input('Where would you like to go...?\n')
state, hero_index = level.move_hero(hero_map_att, move,
level_map.map, map_limit)
hero_map_att[3] = hero_index
level.print_map(level_map.map, hero_map_att, enemy.position,
loot.position, stairs.position, GONE_ROGUE_LOGO)
else:
os.system('cls' if os.name == 'nt' else 'clear')
level.print_map(level_map.map, hero_map_att, enemy.position,
loot.position, stairs.position, GONE_ROGUE_LOGO)
print('\nUse\nw - up\na - left\ns - down\nd -right\nto move...\n')
move = input('Which way...?\n')
state, hero_index = level.move_hero(hero_map_att, move,
level_map.map, map_limit)
hero_map_att[3] = hero_index
level.print_map(level_map.map, hero_map_att, enemy.position,
loot.position, stairs.position, GONE_ROGUE_LOGO)
def success():
"""
Prints dialogue after level 3 game loop is broken
and directs user to the run button should they want to replay"""
os.system('cls' if os.name == 'nt' else 'clear')
print(f"""
Got what was coming to 'em.
Nobody steals {hero.name}'s property...""")
input()
input('\nSEARCH THE ROOM...')
print('\n*fumbling*...')
input()
print(' I knew it...')
input()
os.system('cls' if os.name == 'nt' else 'clear')
print("""
(((((((((((((
/(((((( ((((((.
/(((((( ((((((.
/(((((( ((((((.
/(((((( ((((((.
/(((((( ((((((.
...(((///////(((...
(((((((((((((
(((((((
/(((((((((((((((((((.
......(((((((......
(((((((
(((((((""")
input()
print(' ...this asshole stole THE AMULET.')
input()
input('TAKE THE AMULET...\n')
print("\033[A \033[A")
print("\033[A \033[A")
print(" This'll make a sweet offering in exchange for immortality...")
input()
os.system('cls' if os.name == 'nt' else 'clear')
print(" CONGRATULATIONS")
print(' You have...')
input()
print("""
▄████ ▒█████ ███▄ █ ▓█████
██▒ ▀█▒▒██▒ ██▒ ██ ▀█ █ ▓█ ▀
▒██░▄▄▄░▒██░ ██▒▓██ ▀█ ██▒▒███
░▓█ ██▓▒██ ██░▓██▒ ▐▌██▒▒▓█
░▒▓███▀▒░ ████▓▒░▒██░ ▓██░░▒████▒
░▒ ▒ ░ ▒░▒░▒░ ░ ▒░ ▒ ▒ ░░ ▒░ ░
░ ░ ░ ▒ ▒░ ░ ░░ ░ ▒░ ░ ░ ░
░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░
░ ░ ░ ░ ░ ░""")
input()
print("""
██▀███ ▒█████ ▄████ █ ██ ▓█████
▓██ ▒ ██▒▒██▒ ██▒ ██▒ ▀█▒ ██ ▓██▒▓█ ▀
▓██ ░▄█ ▒▒██░ ██▒▒██░▄▄▄░▓██ ▒██░▒███
▒██▀▀█▄ ▒██ ██░░▓█ ██▓▓▓█ ░██░▒▓█ ▄
░██▓ ▒██▒░ ████▓▒░░▒▓███▀▒▒▒█████▓ ░▒████▒
░ ▒▓ ░▒▓░░ ▒░▒░▒░ ░▒ ▒ ░▒▓▒ ▒ ▒ ░░ ▒░ ░
░▒ ░ ▒░ ░ ▒ ▒░ ░ ░ ░░▒░ ░ ░ ░ ░ ░
░░ ░ ░ ░ ░ ▒ ░ ░ ░ ░░░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░""")
input()
print('CLICK RUN to play again.')
menu()
hero = entity.hero_init()
hero_index = hero.position
print("\033[A \033[A")
print("\033[A \033[A")
# #################Level 1################# #
map_limit = level.largest_index_position(hero.position, enemy.position,
loot.position, stairs.position)
level_map = level.LevelMapGen(map_limit)
hero_map_att = [hero.h_p, hero.power, hero.icon, hero.position]
level.print_map(level_map.map, hero_map_att, enemy.position,
loot.position, stairs.position, GONE_ROGUE_LOGO)
play_level(CHECK_POS)
input('PRESS ENTER to go deeper...\n')
# #################Level 2################# #
hero.position = [(randint(0, 6)), (randint(0, 6))]
hero_map_att[3] = hero.position
enemy, loot, stairs = entity.ents_init(l2[0], l2[1])
map_limit = level.largest_index_position(hero.position, enemy.position,
loot.position, stairs.position)
level_map = level.LevelMapGen(map_limit)
hero_map_att = [hero.h_p, hero.power, hero.icon, hero.position]
level.print_map(level_map.map, hero_map_att, enemy.position,
loot.position, stairs.position, GONE_ROGUE_LOGO)
move = input('\nWhere would you like to go...?\n')
CHECK_POS, hero_index = level.move_hero(hero_map_att, move, level_map.map,
map_limit)
hero_map_att[3] = hero_index
level.print_map(level_map.map, hero_map_att, enemy.position, loot.position,
stairs.position, GONE_ROGUE_LOGO)
play_level(CHECK_POS)
input('PRESS ENTER to go deeper...\n')
# #################Level 3################# #
hero.position = [(randint(0, 6)), (randint(0, 6))]
hero_map_att[3] = hero.position
enemy, loot, stairs = entity.ents_init(l3[0], l3[1])
map_limit = level.largest_index_position(hero.position, enemy.position,
loot.position, stairs.position)
level_map = level.LevelMapGen(map_limit)
hero_map_att = [hero.h_p, hero.power, hero.icon, hero.position]
level.print_map(level_map.map, hero_map_att, enemy.position, loot.position,
stairs.position, GONE_ROGUE_LOGO)
move = input('\nWhere would you like to go...?\n')
CHECK_POS, hero_index = level.move_hero(hero_map_att, move, level_map.map,
map_limit)
hero_map_att[3] = hero_index
level.print_map(level_map.map, hero_map_att, enemy.position, loot.position,
stairs.position, GONE_ROGUE_LOGO)
play_level(CHECK_POS)
success()