-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
483 lines (408 loc) · 16.2 KB
/
main.py
File metadata and controls
483 lines (408 loc) · 16.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
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# Check the about_game() function (in this file) for game credits
## basic story idea:
## you arrive at a town that your friend is in, when the town is under attack.
## you have to get in sneakily to be able to save them, since you find out that he is still in there from his family.
import os
import time
from pathlib import Path
from subprocess import call
## ## Regular Important Libraries
from rich.console import Console
from rich.prompt import Confirm
## # The game itself
import game
## ## Game Libraries
## # Graphics
import graphics
## # Languages
import languages
## # Saving and Player Data
import save_data
from game import game_save, language
## # Utilities
from utils import string_with_vars_handler, typewriter
console = Console()
## HELP_MSG = """[bold]HELP:[/]
## No Help Available (so leave me alone)"""
def load_save_data() -> bool:
"""Loads the game data
(not to be confused with the load save function in the save_data module)
:returns: Returns False if save data doesn't exist,
and if save data doesn't have a language saved (just in case)"""
global game_save, language
file_location = Path(save_data.SAVE_DATA_FILE)
save = dict
if file_location.is_file():
save = save_data.load_data()
else:
return False
if not os.path.isdir(save_data.SAVE_DATA_FOLDER):
return False
## Nice
if save["LANGUAGE"] == -69:
return False
language = languages.load_language(save["LANGUAGE"])
game_save = save
return True
def clear_screen():
"""You don't really need docstrings, since my ass code makes things more verbose, but I'm putting some in places anyway."""
if os.name == "posix": # posix = linux
_ = call("clear")
else:
_ = call("cmd /C cls")
def get_player_input() -> str:
## Important for later
command_requested = ""
## Player Input
val = str(console.input(">")).lower().strip()
## Check for valid commands
if val == "help":
console.print(language["HELP_IN-GAME"])
elif val == "exit":
if Confirm.ask("Exit the game?"):
console.print("Goodbye!")
exit(0)
elif val == "":
console.print("[red]No command given.[/]")
else:
console.print(f"[red]Unknown command: {val}[/]")
return command_requested
def about_game():
## Maybe this may change...
typewriter(
"""PythonTextRPG:
Designed, Programmed, and Writen by: Kamie!
Some game design choices from : The people in my Discord Server!
Socials:
My Website : https://kamies-blog.netlify.app
Discord Server: https://discord.gg/saZqeK2m9d"""
)
# def color_typewriter(string, speed=0.05, end="\n"):
# for char in string:
# console.print(char, end="")
# time.sleep(speed)
# print("", end=end)
def character_generator():
clear_screen()
print(graphics.TITLE_SCREEN)
typewriter(language["CHAR_GEN"]["NAME"]["QUESTION"])
name = ""
while True:
name = str(console.input(">")).strip()
if name == "":
typewriter(f"{language['ERROR']['PREFIX']} ", end="", style="red")
typewriter(language["ERROR"]["CHAR_GEN"]["NAME_EMPTY"])
continue
elif name.lower() == "help":
typewriter(f"{language['HELP']['PREFIX']}", style="bold")
typewriter(language["HELP"]["CHAR_GEN"]["NAME"])
continue
break
clear_screen()
print(graphics.TITLE_SCREEN)
typewriter(language["CHAR_GEN"]["GENDER"]["QUESTION"])
typewriter(f"1: {language['CHAR_GEN']['GENDER']['MALE']}")
typewriter(f"2: {language['CHAR_GEN']['GENDER']['FEMALE']}")
typewriter(f"3: {language['CHAR_GEN']['GENDER']['OTHER']}")
gender = ""
while True:
gender = str(console.input(">")).strip()
if gender == "1" or gender == "2" or gender == "3":
break
elif gender.lower() == "help":
typewriter(f"{language['HELP']['PREFIX']}", style="bold")
typewriter(language["HELP"]["CHAR_GEN"]["GENDER"])
continue
else:
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
clear_screen()
print(graphics.TITLE_SCREEN)
typewriter(language["CHAR_GEN"]["CLASS"]["QUESTION"])
typewriter(f"1: {language['CHAR_GEN']['CLASS']['SWORDSMAN']}")
typewriter(f"2: {language['CHAR_GEN']['CLASS']['RANGER']}")
typewriter(f"3: {language['CHAR_GEN']['CLASS']['WIZARD']}")
typewriter(f"4: {language['CHAR_GEN']['CLASS']['ALL-ROUNDER']}")
charclass = ""
while True:
charclass = str(console.input(">")).strip()
if charclass == "1" or charclass == "2" or charclass == "3" or charclass == "4":
break
elif charclass.lower() == "help":
typewriter(f"{language['HELP']['PREFIX']}", style="bold")
typewriter(language["HELP"]["CHAR_GEN"]["CLASS"])
else:
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
clear_screen()
print(graphics.TITLE_SCREEN)
## this whole section looks like ass, i know
typewriter(language["CHAR_GEN"]["CONFIRM"]["TO_CONFIRM"], end="")
typewriter(language["CHAR_GEN"]["CONFIRM"]["DOT_DOT_DOT"], speed=0.5)
typewriter(f"{language['CHAR_GEN']['CONFIRM']['NAME']} {name}")
selected_gender = ""
if gender == "1":
selected_gender = language["CHAR_GEN"]["GENDER"]["MALE"]
elif gender == "2":
selected_gender = language["CHAR_GEN"]["GENDER"]["FEMALE"]
elif gender == "3":
selected_gender = language["CHAR_GEN"]["GENDER"]["OTHER"]
typewriter(f"{language['CHAR_GEN']['CONFIRM']['GENDER']} {selected_gender}")
selected_class = ""
if charclass == "1":
selected_class = language["CHAR_GEN"]["CLASS"]["SWORDSMAN"]
elif charclass == "2":
selected_class = language["CHAR_GEN"]["CLASS"]["RANGER"]
elif charclass == "3":
selected_class = language["CHAR_GEN"]["CLASS"]["WIZARD"]
elif charclass == "4":
selected_class = language["CHAR_GEN"]["CLASS"]["ALL-ROUNDER"]
typewriter(f"{language['CHAR_GEN']['CONFIRM']['CLASS']} {selected_class}")
typewriter(language["CHAR_GEN"]["CONFIRM"]["DOT_DOT_DOT"], speed=0.5, end="")
typewriter(f"{language['CHAR_GEN']['CONFIRM']['IS_CORRECT']} (y/n)")
confirm = ""
while True:
confirm = str(console.input(">")).strip().lower()
if confirm == "y" or confirm == "n":
break
if confirm == "yes":
confirm = "y"
break
elif confirm == "no":
confirm = "n"
break
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
if confirm == "y":
print("unfished")
exit(1)
else:
character_generator()
## Checks if the main menu hasn't been loaded yet.
## If it hasn't, then it prints the title screen with typewriter(), otherwise it uses print()
main_menu_first_load_check_yes_why_am_i_making_this_name_long = False
def load_save_selector():
save1label = string_with_vars_handler(
language["MAIN_MENU"]["SAVE_SELECTION"]["SAVE_LABEL"], "#", "1"
)
save2label = string_with_vars_handler(
language["MAIN_MENU"]["SAVE_SELECTION"]["SAVE_LABEL"], "#", "2"
)
save3label = string_with_vars_handler(
language["MAIN_MENU"]["SAVE_SELECTION"]["SAVE_LABEL"], "#", "3"
)
print(graphics.TITLE_SCREEN)
typewriter(
language["MAIN_MENU"]["SAVE_SELECTION"]["QUESTIONS"]["LOAD_SAVE_QUESTION"]
)
typewriter(f"1: {save1label}")
typewriter(f"2: {save2label}")
typewriter(f"3: {save3label}")
typewriter(f"4: {language['OTHER']['OPTIONS']['GO_BACK']}")
def new_or_load_game():
print(graphics.TITLE_SCREEN)
typewriter(language["MAIN_MENU"]["START_GAME_SUB"]["NEW_OR_LOAD_QUESTION"])
typewriter(f"1: {language['MAIN_MENU']['START_GAME_SUB']['NEW_GAME']}")
typewriter(f"2: {language['MAIN_MENU']['START_GAME_SUB']['LOAD_GAME']}")
typewriter(f"3: {language['OTHER']['OPTIONS']['GO_BACK']}")
ask = ""
while True:
ask = str(console.input(">")).lower().strip()
if ask == "1" or ask == "2" or ask == "3":
break
elif ask == "back" or ask == "q": ## fix muscle memory issues
ask = "3"
break
elif ask == "help":
## those who know: skull
typewriter(f"{language['HELP']['PREFIX']}", style="bold")
typewriter(language["HELP"]["MAIN_MENU"])
else:
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
if ask == "1":
clear_screen()
character_generator()
elif ask == "2":
clear_screen()
load_save_selector()
elif ask == "3":
clear_screen()
main_menu()
typewriter_settingsmenu_title = False
def settings_menu():
global typewriter_settingsmenu_title
clear_screen()
if not typewriter_settingsmenu_title:
print(graphics.TITLE_SCREEN)
else:
typewriter(graphics.TITLE_SCREEN)
typewriter_settingsmenu_title = False
typewriter(
f"1: {language['MAIN_MENU']['SETTINGS_SUB']['CHANGE_LANGUAGE']} {language['MAIN_MENU']['SETTINGS_SUB']['CURRENT_LANGUAGE']}"
)
typewriter(f"2: {language['MAIN_MENU']['SETTINGS_SUB']['DELETE_SAVE']}")
typewriter(f"3: {language['OTHER']['OPTIONS']['GO_BACK']}")
ask = ""
while True:
ask = str(console.input(">")).lower().strip()
if ask == "1" or ask == "2" or ask == "3" or ask == "back" or ask == "q":
break
elif ask == "help":
## those who know: skull
typewriter(f"{language['HELP']['PREFIX']}", style="bold")
typewriter(language["HELP"]["MAIN_MENU"])
else:
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
if ask == "1":
clear_screen()
language_selector()
typewriter_settingsmenu_title = True
settings_menu()
elif ask == "2":
clear_screen()
typewriter(
language["OTHER"]["DELETE_SAVE_MESSAGE"],
style="red italic not bold",
)
typewriter("(y/n)", style="red not bold")
confirm = ""
while True:
confirm = str(console.input(">")).strip().lower()
if confirm == "y" or confirm == "n":
break
if confirm == "yes":
confirm = "y"
break
elif confirm == "no":
confirm = "n"
break
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
if confirm == "y":
typewriter("Deleting save in 5...", style="red", end="")
time.sleep(1)
typewriter("4...", speed=0, style="red", end="")
time.sleep(1)
typewriter("3...", speed=0, style="red", end="")
time.sleep(1)
typewriter("2...", speed=0, style="red", end="")
time.sleep(1)
typewriter("1...", speed=0, style="red", end="")
time.sleep(1)
print()
file_location = Path(save_data.SAVE_DATA_FILE)
if not file_location.is_file():
typewriter(
language["ERROR"]["FALLBACK"]["SAVE_DELETE_BUT_SAVE_DOES_NOT_EXIST"]
)
exit(1)
os.remove(file_location.name)
typewriter("Save deleted! Closing the game...")
exit(0)
clear_screen()
typewriter_settingsmenu_title = True
settings_menu()
else:
clear_screen()
main_menu()
def main_menu():
global main_menu_first_load_check_yes_why_am_i_making_this_name_long
if not main_menu_first_load_check_yes_why_am_i_making_this_name_long:
typewriter(graphics.TITLE_SCREEN)
main_menu_first_load_check_yes_why_am_i_making_this_name_long = True
else:
print(graphics.TITLE_SCREEN)
typewriter(f"1: {language['MAIN_MENU']['START_GAME']}", end="")
# console.print(
# "[black not bold](v0.0.0 \[pre-alpha])[/]"
# ) ## i hate that it keeps complaining here about "\["
typewriter("(v0.0.1 [pre-alpha])", style="black not bold")
typewriter(f"2: {language['MAIN_MENU']['ABOUT']}")
typewriter(f"3: {language['MAIN_MENU']['SETTINGS']}")
typewriter(f"4: {language['MAIN_MENU']['EXIT_GAME']}")
ask = ""
while True:
ask = str(console.input(">")).lower().strip()
# yandere dev ass if statement
if ask == "1" or ask == "2" or ask == "3" or ask == "4":
if ask != "2":
break
else:
about_game()
elif ask == "exit" or ask == "quit" or ask == "q": ## fix muscle memory issues
ask = "4"
break
elif ask == "help":
typewriter(f"{language['HELP']['PREFIX']}", style="bold")
typewriter(language["HELP"]["MAIN_MENU"])
elif ask == "debug":
if game.DEBUG_MODE:
game.item_message_handler("GOT_ITEM", "Eel")
input("pause")
# chat = utils.npc.Conversation(
# "NPC",
# ["Hi!", "Nice weather we are having huh?"],
# ["Yeah!", "No it sucks."],
# )
# get_response = chat.start_conversation()
# if get_response == "1":
# chat = utils.npc.Conversation("NPC", ["Yeah..."])
# _ = chat.start_conversation()
# elif get_response == "2":
# chat = utils.npc.Conversation(
# "NPC", ["Well, that sucks for you..."]
# )
# _ = chat.start_conversation()
else:
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
else:
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
if ask == "1":
clear_screen()
new_or_load_game()
elif ask == "3":
settings_menu()
elif ask == "4":
typewriter(language["OTHER"]["EXIT_MSG"])
exit(0)
def language_selector():
global language
lang_index = 0
typewriter("What language do you want to use?")
for index in range(languages.amount_of_languages_in_list()):
index_plus_1 = index + 1
temp_lang = languages.load_language(index)
typewriter(f"{index_plus_1}: {temp_lang['NAME']}")
ask = ""
while True:
ask = str(console.input(">")).lower().strip()
ask_int = 0
if ask.isdigit():
ask_int = int(ask)
if languages.amount_of_languages_in_list() >= ask_int > 0:
lang_index = ask_int - 1
language = languages.load_language(lang_index)
break
typewriter(f"{language['ERROR']['PREFIX']}", end="", style="red")
typewriter(f" {language['ERROR']['NOT_OPTION']}")
game_save["LANGUAGE"] = lang_index
save_data.save_data(game_save)
def main():
# while True:
# request = get_player_input()
# console.print(request)
if not load_save_data():
save_data.create_save_folder()
clear_screen()
language_selector()
clear_screen()
main_menu()
if __name__ == "__main__":
main()
else:
print("This game cannot run as a module! Force quitting program...")
exit(1)