-
Notifications
You must be signed in to change notification settings - Fork 1
/
lifeordeath.py
458 lines (404 loc) · 15.6 KB
/
lifeordeath.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
#!/usr/bin/env python
import jsonpickle
import textwrap
import random
import time
import sys
import os
#Variables
SAVEGAME_FILENAME = 'savegame.json'
game_state = dict()
### Classes ###
class Human(object):
#Represents the human player in the game
def __init__(self, name, health, strength, gold):
self.name = name
self.health = health
self.strength = strength
self.gold = gold
class AI(object):
#Represents the enemy player in the game
def __init__(self, name, health, strength):
self.name = name
self.health = health
self.strength = strength
class creature(object):
#Represents the enemy player in the game
def __init__(self, type, name, health, strength, weakness):
self.name = name
self.health = health
self.strength = strength
class Items:
def __init__(self, name, info, weight):
self.name = name
self.info = info
self.weight = weight
###end classess###
###functions for loading, saving, and initializing the game###
def load_game():
"""Load game state from a predefined savegame location and return the
game state contained in that savegame.
"""
with open(SAVEGAME_FILENAME, 'r') as savegame:
state = jsonpickle.decode(savegame.read())
return state
def save_game():
"""Save the current game state to a savegame in a predefined location.
"""
global game_state
with open(SAVEGAME_FILENAME, 'w') as savegame:
savegame.write(jsonpickle.encode(game_state))
def init_game():
"""If no savegame exists, initialize the game state with some
default values.
"""
global game_state
player = Human('Fred', 100, 10, 1000)
enemy = AI('Imp', 50, 20)
state = dict()
state['players'] = [player]
state['npcs'] = [enemy]
return state
###End functions for loading, saving, and initalizing the game###
# Commands = {
# 'quit': Player.quit,
# 'help': Player.help,
# 'status': Player.status,
# 'rest': Player.rest,
# 'examine': Player.examine,
# 'attack': Player.attack,
# }
def _clear():#clear screen function
os.system('cls' if os.name == 'nt' else 'clear')
#The main game loop
def Game_Loop():
global game_state
while True:
_clear()
time.sleep(0.2)
print("/:::::::::::::::::::::::::::::::::::::::\ ")
print(":::::: Welcome To Life or Death ::::::| ")
print(":::::::::::::: The Game ::::::::::::::|" )
print("\:::::::::::::::::::::::::::::::::::::::/ ")
print("")
print(" |(1) New Game\n |(2) Load Save\n |(3) Help For Dummies\n |(4) RAGE QUIT\n ")
time.sleep(1.0)
try:
selection = int(input(">>> "))
except ValueError:
print()
print("You can only use numbers 1, 2, 3, or 4.")
print()
_clear()
Game_Loop()
if selection == 1:
_clear()
init_game()
elif selection == 2:
_clear()
load_game()
elif selection == 3:
_clear()
help_menu()
elif selection == 4:
_clear()
rage_quit()
else:
Game_Loop()
def help_menu():
"Help Menu"
_clear()
print("""
/~~~~~~~~~~~~~~~~~~~|
| Welcome To The |
|Help Menu For Noobs|
|===================|
| (1) Main Menu |
| (2) Extra Tips |
|===================|
|01)
|02)
|03)
|04)
|05)
|06)
|07)
|08)
|09)
|10)
|11)
|12)
|13)
|14)
|15)
|~~~~~~~~~~~~~~~~~~~/""")
time.sleep(0.5)
option = input(' --> ')
if option == '1':
main_menu()
elif option == '2':
hints()
else:
help_menu()
def rage_quit():
"Quit Sequence"
_clear()
time.sleep(0.4)
print("""
/~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| R A G E Q U I T |
| ^ ^ ^ ^ ^ ^ ^ ^ |
|============================|
| (1) Y E S ? |
| (2) N O ? |
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~/""")
time.sleep(1.0)
option = input(' --> ')
if option == '1':
_clear()
time.sleep(0.2)
print("""
-
""")
time.sleep(0.3)
_clear()
print("""
\
""")
time.sleep(0.3)
_clear()
print("""
|
""")
time.sleep(0.3)
_clear()
print("""
/
""")
time.sleep(0.3)
_clear()
print("""
-
""")
time.sleep(0.3)
_clear()
print("""
\
""")
time.sleep(0.3)
_clear()
print("""
|
""")
time.sleep(0.3)
_clear()
print("""
/
""")
time.sleep(0.3)
_clear()
print("""
-
""")
time.sleep(0.3)
_clear()
print("""
\
""")
time.sleep(0.3)
_clear()
print("""
|
""")
time.sleep(0.3)
_clear()
print("""
/
""")
time.sleep(0.3)
_clear()
print("""
-
""")
time.sleep(0.3)
_clear()
print("""
\
""")
time.sleep(0.3)
_clear()
print("""
*
""")
time.sleep(0.8)
_clear()
print("""
###########################################
--------->[ W A R N I N G ]<---------
| E M E R G E N C Y S H U T D O W N |
| I M M I N E N T |
###########################################
[ ]
0%
""")
time.sleep(3.0)
_clear()
print("""
###########################################
--------->[ W A R N I N G ]<---------
| E M E R G E N C Y S H U T D O W N |
| I M M I N E N T |
###########################################
[▆▆▆ ]
5%
""")
time.sleep(2.0)
_clear()
print("""
###########################################
--------->[ W A R N I N G ]<---------
| E M E R G E N C Y S H U T D O W N |
| I M M I N E N T |
###########################################
[▆▆▆▆▆▆▆ ]
20%
""")
time.sleep(5.0)
_clear()
print("""
###########################################
--------->[ W A R N I N G ]<---------
| E M E R G E N C Y S H U T D O W N |
| I M M I N E N T |
###########################################
[▆▆▆▆▆▆▆▆▆▆▆▆▆ ]
47%
""")
time.sleep(4.0)
_clear()
print("""
###########################################
--------->[ W A R N I N G ]<---------
| E M E R G E N C Y S H U T D O W N |
| I M M I N E N T |
###########################################
[▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ ]
68%
""")
time.sleep(5.0)
_clear()
print("""
###########################################
--------->[ W A R N I N G ]<---------
| E M E R G E N C Y S H U T D O W N |
| I M M I N E N T |
###########################################
[▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ ]
99%
""")
time.sleep(7.0)
_clear()
print("""
###########################################
--------->[ W A R N I N G ]<---------
| E M E R G E N C Y S H U T D O W N |
| I M M I N E N T |
###########################################
[▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆]
100%
""")
time.sleep(2.0)
_clear()
print("""
▆===`~!#44 ===== ▆▆ ▆▆▆= ==▆====▆====▆▆\^^#!~) ======▆▆▆ ▆=== ====▆▆▆▆ === =▆ ▆▆▆
▆▆▆ ▆▆747%*&}`67$^#% ▆▆▆▆▆▆ ▆E R R O▆ R▆▆▆ 4 0▆ 4▆▆▆ ▆\ ▆▆▆ ▆▆455563dll▆▆
▆▆▆ = ▆▆▆ ▆ @@# R%$% ▆▆ ▆= ▆▆▆▆ ▆▆▆▆▆▆▆ ▆ ▆▆▆▆ ▆!!46i58i4▆▆▆
▆▆ 7t7r6t%^&**▆▆ S▆O C I▆A L ▆ L I F E N O▆T F O▆U N D ▆▆▆
=▆▆▆=▆▆▆▆=== ==▆▆======= =====▆========= ===▆▆▆ ▆▆=====▆▆=▆▆▆▆▆ ▆▆▆▆▆▆=▆▆ ut▆▆r%^^8▆▆
""")
time.sleep(4.5)
print(" Thanks For Playing!!! :D ")
time.sleep(2.5)
sys.exit()
elif option == '2':
main_menu()
else:
rage_quit()
def hints():
"Extra Help Menu"
print("""
/~~~~~~~~~~~~~~~~~~~~~~~~~|
| More Help |
| For Noobs |
|=========================|
| (1) Main Menu |
|=========================|
|01)
|02)
|03)
|04)
|05)
|06)
|07)
|08)
|09)
|10)
|11)
|12)
|13)
|14)
|15)
|~~~~~~~~~~~~~~~~~~~~~~~~/""")
option = input(' --> ')
if option == '1':
main_menu()
else:
return
def title_pic():
"Title Text Picture"
_clear()
time.sleep(1.5)
print("""
:::8888888888888888888888888888888P""""""48888888888888888888888::::88
::::8888888888888888888888P ____.------.____ 488888888888888:::888
::::88888888888888888P __.--"" _._ ""--.__ 4888888888:::888
:::::888888888888P _.-" .-~ | ~-. "-._ 488888:::888
:::::888888888P _-" | | | "-_ 488::8888
::::::888888P ,' | _:_ | .-:~--.._8
8:::::88888 ,' . .-"~~ | ~~"-. .~ | |
88:::::88P /_.-~:. . : | | | . | | |
888::::8P /| | `.o ! | | | : | | |
8P_..--~:-.| | | d | | | . o | | |
8| | ~. | | o | __.:.__ | ; b | | |
8| | | | | d8 .-"~~ | ~~"-.o 8 | | |
8| | | _|.--~:-98 | | |8b 8.:~-.| | |
8| A | | | ~. | | _.-:~--._ .' | | | |
8| M | | | | | | | | | | | | | |
8| C | | | | | | | | | | | | O |
8| | | | | | | | | | | | | | j |
8| 9 | | | | | | | | | | | | o |
8| 9 | | | | | | | | | | | | | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""")
time.sleep(6.0)
Game_Loop()
def start():
"Start story"
_clear()
choice1 = ''
print("gg")
###End main game functions###
###The "main" function, not to be confused with anything to do with main above it###
def main():
"""Main function. Check if a savegame exists, and if so, load it. Otherwise
initialize the game state with defaults. Finally, start the game.
"""
global game_state
if not os.path.isfile(SAVEGAME_FILENAME):
game_state = initialize_game()
else:
game_state = load_game()
Game_Loop()
if __name__ == '__main__':
main()
###end main function###
title_pic()