-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
1497 lines (1417 loc) · 68.1 KB
/
Copy pathmain.py
File metadata and controls
1497 lines (1417 loc) · 68.1 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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import time # Used for pausing the game with time.sleep()
import os # Used for clearing the console with os.system('cls' or 'clear')
import random # Used for shuffling lists (e.g., support_options in display_location)
import json # Used for loading and saving JSON data (e.g., load_dialogue, save_game, load_game)
import platform # Used for detecting the operating system (e.g., in install_library, clear_console)
import requests # Used for making HTTP requests (e.g., in load_cn_tower_art, load_dialogue, get_user_country)
import subprocess # Used for running shell commands (e.g., in install_library to run pip or pip3)
from art import text2art # Used for generating ASCII art (in main to display "CN Tower")
from prompt_toolkit import PromptSession # Used for creating a session with command history support
# GitHub Repository Details
# Replace 'cherrywheel' with your actual GitHub username if it's different
GITHUB_USERNAME = "cherrywheel"
GITHUB_REPO = "CN-Tower"
DIALOGUE_URL = f"https://raw.githubusercontent.com/{GITHUB_USERNAME}/{GITHUB_REPO}/main/dialogue.json" # URL to fetch dialogue data from GitHub
CN_TOWER_ART_URL = f"https://raw.githubusercontent.com/{GITHUB_USERNAME}/{GITHUB_REPO}/main/cn_tower_art.txt" # URL to fetch CN Tower ASCII art from GitHub
# List of countries where certain game features are restricted
RESTRICTED_COUNTRIES = [
"Afghanistan", "Brunei", "Gambia", "Iran", "Iraq", "Jamaica", "Kenya",
"Libya", "Malaysia", "Nigeria", "Pakistan", "Qatar", "Saudi Arabia",
"Sudan", "Somalia", "Tanzania", "Uganda", "Yemen", "Zambia",
"Zimbabwe", "Russia", "Hungary", "Georgia", "Bulgaria"
]
def clear_console():
"""Clears the console screen.
Uses 'cls' command on Windows and 'clear' on other systems (like Linux or macOS).
"""
if platform.system() == "Windows":
os.system('cls') # Clear console on Windows
else:
os.system('clear') # Clear console on Linux/macOS
def install_library(library_name):
"""Installs a library using pip or pip3.
Args:
library_name (str): The name of the library to install.
"""
print(f"Installing {library_name}...")
if platform.system() == "Windows":
subprocess.check_call(["pip", "install", library_name]) # Use pip on Windows
else: # Assume Linux or macOS
subprocess.check_call(["pip3", "install", library_name]) # Use pip3 on Linux/macOS
def check_libraries():
"""Checks for required libraries and installs them if missing."""
required_libraries = ["requests", "art"] # List of required libraries
for library in required_libraries:
try:
__import__(library) # Try to import the library
except ImportError:
print(f"Missing library: {library}")
install_library(library) # Install the missing library
def load_cn_tower_art():
"""Loads CN Tower art from a remote URL.
Returns:
str: The CN Tower art as a string, or None if an error occurred.
"""
try:
response = requests.get(CN_TOWER_ART_URL) # Send GET request to the art URL
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
return response.text # Return the art as a string
except requests.exceptions.RequestException as e:
print(f"Error loading CN Tower art: {e}")
return None
def display_cn_tower_art(art):
"""Displays the CN Tower art.
Args:
art (str): The CN Tower art to display.
"""
if art:
print(art) # Print the art if it was loaded successfully
else:
print("Could not load CN Tower art.")
# Create a global session to preserve command history
session = PromptSession()
def get_player_input():
"""Gets input from the user with command history support."""
try:
return session.prompt("> ").lower()
except EOFError:
return "exit"
def has_item(inventory, item):
"""Checks if an item exists in the inventory.
Args:
inventory (dict): The player's inventory.
item (str): The item to check for.
Returns:
bool: True if the item exists, False otherwise.
"""
return item in inventory # Returns True if item is a key in the inventory dictionary
def add_item(inventory, item, value=True):
"""Adds an item to the inventory.
Args:
inventory (dict): The player's inventory.
item (str): The item to add.
value (optional): The value associated with the item. Defaults to True.
"""
inventory[item] = value # Add the item to the inventory dictionary
def remove_item(inventory, item):
"""Removes an item from the inventory.
Args:
inventory (dict): The player's inventory.
item (str): The item to remove.
"""
if item in inventory:
del inventory[item] # Remove the item from the inventory dictionary
def display_inventory(inventory):
"""Displays the player's inventory.
Args:
inventory (dict): The player's inventory.
"""
print("Inventory:", inventory) # Print the inventory dictionary
def save_game(location, inventory, filename="savegame.json"):
"""Saves the game state to a JSON file.
Args:
location (str): The current location of the player.
inventory (dict): The player's inventory.
filename (str, optional): The name of the save file. Defaults to "savegame.json".
"""
try:
with open(filename, "w", encoding="utf-8") as f: # Specify encoding as UTF-8
json.dump({"location": location, "inventory": inventory}, f) # Save location and inventory to JSON file
print("Game saved.")
except Exception as e:
print(f"Error saving game: {e}")
def load_game(filename="savegame.json"):
"""Loads the game state from a JSON file.
Args:
filename (str, optional): The name of the save file. Defaults to "savegame.json".
Returns:
tuple: The loaded location and inventory, or ("base", {"money": 40}) if no save file is found or an error occurs.
"""
try:
with open(filename, "r", encoding="utf-8") as f: # Specify encoding as UTF-8
data = json.load(f) # Load location and inventory from JSON file
print("Game loaded.")
return data["location"], data["inventory"] # Return the loaded location and inventory
except (FileNotFoundError, json.JSONDecodeError):
print("No saved game found. Starting new game.")
return "base", {"money": 40} # Return default values for a new game
except Exception as e:
print(f"Error loading game: {e}. Starting new game.")
return "base", {"money": 40} # Return default values for a new game
def load_dialogue():
"""Loads dialogue data from a remote JSON file.
Returns:
dict: The dialogue data, or an empty dictionary if an error occurred.
"""
try:
response = requests.get(DIALOGUE_URL) # Send GET request to the dialogue URL
response.raise_for_status()
return response.json() # Return the dialogue data as a dictionary
except requests.exceptions.RequestException as e:
print(f"Error loading dialogue: {e}")
return {} # Return an empty dictionary if loading fails
rate_limited_apis = {}
def get_user_country():
"""Detects the user's country using multiple external APIs without API keys.
If an API returns 429 (Too Many Requests), it is blocked for 5 minutes.
After 5 minutes, that API is retried.
Returns:
str: The detected country name, or None if not determined.
"""
apis = [
"https://ipapi.co/json/",
"https://ipwho.is/",
"https://freegeoip.app/json/"
]
now = time.time()
for api_url in apis:
# Skip API if it's still rate-limited
if api_url in rate_limited_apis and now < rate_limited_apis[api_url]:
continue
try:
response = requests.get(api_url, timeout=5) # 5-second timeout
if response.status_code == 429:
# Block the API for 5 minutes without printing a notification
rate_limited_apis[api_url] = now + 5 * 60
continue
response.raise_for_status()
data = response.json()
if "country_name" in data:
return data.get("country_name", "")
elif "country" in data:
return data.get("country", "")
else:
print(f"Unexpected response format from {api_url}")
except requests.exceptions.RequestException as e:
print(f"Error with {api_url} (RequestException): {e}")
print("Could not determine country from APIs. Trying timezone...")
try:
import pytz
from datetime import datetime
local_timezone = datetime.now().astimezone().tzinfo
country_code = pytz.country_timezones.get(str(local_timezone))
if country_code:
return pytz.country_names.get(country_code[0].upper())
except ImportError:
print("Missing library: pytz. Please install it (pip install pytz)")
except Exception as e:
print(f"Error getting country from timezone: {e}")
print("Could not determine user's country.")
return None
def is_country_banned(user_country, banned_countries):
"""Checks if the user's country is in the banned list.
Args:
user_country (str): The user's country name.
banned_countries (list): The list of banned countries.
Returns:
bool: True if the user's country is banned, False otherwise.
"""
return user_country in banned_countries
def sweet_dialogue(text, location, sweet_mode, dialogue_data):
"""Modifies dialogue based on sweet+ mode and location using loaded dialogue data.
Args:
text (str): The original text.
location (str): The current location in the game.
sweet_mode (bool): Whether sweet+ mode is enabled.
dialogue_data (dict): The loaded dialogue data.
Returns:
str: The modified text if sweet+ mode is enabled and a modification exists, otherwise the original text.
"""
if not sweet_mode:
return text # Return the original text if sweet+ mode is off
if location in dialogue_data:
for key, value in dialogue_data[location].items():
text = text.replace(key, value) # Replace placeholders with sweet+ dialogue
return text
def display_debug_menu(inventory, sweet_mode, is_restricted):
"""Displays the debug menu and handles debug commands.
Args:
inventory (dict): The player's inventory.
sweet_mode (bool): Whether sweet+ mode is enabled.
is_restricted (bool): Whether the user is in a restricted country.
"""
valid_items = ["ticket", "mask", "edgewalk_ticket", "postcards", "souvenir", "bible", "alex_phone"]
while True:
print("\n--- Debug Menu ---")
print("1. Add Money")
print("2. Add Item")
print("3. Remove Item")
print("4. Set Location")
print("5. View Inventory")
print("6. Exit Debug Menu")
if not is_restricted:
print("7. Toggle Sweet+ Mode")
choice = input("Enter choice: ")
if choice == "1":
amount = int(input("Enter amount of money to add: "))
inventory["money"] += amount
print(f"Added ${amount}. Current money: ${inventory['money']}")
elif choice == "2":
print("Available items:", ", ".join(valid_items))
item = input("Enter item name to add: ")
if item in valid_items:
add_item(inventory, item)
print(f"{item} added to inventory.")
else:
print("Invalid item name.")
elif choice == "3":
item = input("Enter item name to remove: ")
remove_item(inventory, item)
print(f"{item} removed from inventory.")
elif choice == "4":
location = input("Enter the location to set: ")
return location, inventory, sweet_mode
elif choice == "5":
display_inventory(inventory)
elif choice == "6":
print("Exiting debug menu...")
return None, inventory, sweet_mode
elif choice == "7" and not is_restricted:
sweet_mode = not sweet_mode
print(f"sweet+ Mode {'enabled' if sweet_mode else 'disabled'}")
else:
print("Invalid choice.")
def display_location(location, inventory, sweet_mode, dialogue_data):
"""Displays a description of the current location, inventory, and available actions.
Handles the display of dialogue, taking into account sweet mode and location-specific dialogue.
Args:
location (str): The current location in the game.
inventory (dict): The player's inventory.
sweet_mode (bool): Whether sweet+ mode is enabled.
dialogue_data (dict): The loaded dialogue data.
"""
print("\n---")
if location == "base":
# Display initial description of the base location
text = "You're at the base of the CN Tower. It's huge!"
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
text = "Entrance is North. Gift shop is East."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
if not inventory.get("met_alex", False):
text = "You see a person who looks like they want to talk (West)."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
if "worker_task" not in inventory and not inventory.get("met_Patrick", False):
text = "A worker is struggling with some boxes (South)."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
if inventory.get("met_Patrick", True):
text = "You see a strange guy, he looks like a club member (West)"
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Go North', 'Go East', 'Go West', 'Go South', 'Look Around', 'Inventory', 'Help', 'Exit', 'Restart', 'Debug', 'Save', 'Load'."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
elif location == "alex_rivers":
if not inventory.get("met_alex", False):
# Initial interaction with Alex Rivers
text = "You go to the person. They say their name is Alex Rivers."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
text = '"Hey! Nice day to visit the CN Tower, right?"'
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
time.sleep(3)
text = 'Alex checks their watch. "It\'s 17:46. I have 5 minutes to record a video for my social media channel."'
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
time.sleep(5)
text = "Alex talks a lot about the weather, the view, and their love for the CN Tower."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
for i in range(5):
text = f"...blah, blah, blah! ({5 - i} minutes)"
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
time.sleep(3)
text = "...Alex looks at their watch."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
text = '"Oh no! I lost track of time. Gotta run!"'
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
time.sleep(2)
text = "You wasted a lot of time."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
text = "You continue your tour."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
inventory["met_alex"] = True
if not has_item(inventory, "ticket"):
text = "Also, you don't have much time, so you didn't buy a ticket."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
return "base"
else:
return "security"
else:
# Subsequent interaction with Alex Rivers
text = "It's Alex Rivers again. Still talking about the CN Tower."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
text = 'Alex: "Oh, it\'s you! Enjoying the tower? It\'s great, right?"'
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
# Options for interacting with Alex
support_options = [
"This tower is truly a marvel of engineering!",
"The view from up here is absolutely breathtaking!",
"You're doing a great job promoting this place, Alex!",
"I've never seen anything like this before!",
"This is the best day of my life!"
]
if sweet_mode:
# Apply sweet_dialogue to each support option
support_options = [sweet_dialogue(option, "alex_rivers", sweet_mode, dialogue_data) for option in support_options]
random.shuffle(support_options)
best_support = "You're doing a great job promoting this place, Alex!"
if sweet_mode:
best_support = sweet_dialogue(best_support, "alex_rivers", sweet_mode, dialogue_data)
if best_support not in support_options:
support_options[-1] = best_support
print("Choose two ways to support Alex:")
for i, option in enumerate(support_options):
print(f"{i + 1}. {option}")
choices = []
while len(choices) < 2:
try:
choice = int(input(f"Enter choice {len(choices) + 1}: ")) - 1
if 0 <= choice < len(support_options):
choices.append(support_options[choice])
else:
print("Invalid choice. Pick a number from the list.")
except ValueError:
print("Invalid input. Enter a number, please.")
print("You say:")
for choice in choices:
print(f"- {choice}")
time.sleep(2)
# Check if the best support option was chosen
if best_support in choices:
text = 'Alex: "Wow, you think so? That\'s awesome! Here, take $40. Also i\'ll give you a ticket and a mask"'
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
inventory["money"] += 40
add_item(inventory, "mask")
add_item(inventory, "ticket")
else:
text = 'Alex: "Thanks! Every little bit helps."'
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Compliment Alex', 'Ignore', 'Exit', 'Restart'."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
# (Continue with other locations in the same detailed manner)
elif location == "Patrick":
text = "You go to the strange guy. He says his name is Patrick."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
text = '"Hey! You look like you\'ve got energy. Join our quadrobics club?"'
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
time.sleep(3)
text = "Patrick shows some quadrobics moves."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Join', 'Decline', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
elif location == "entrance":
text = "You're at the entrance. There's a long line for tickets."
text = sweet_dialogue(text, "entrance", sweet_mode, dialogue_data)
print(text) # Print after the sweet+ dialogue
if has_item(inventory, "ticket"):
text = "You have a ticket! Go to security check (North)."
text = sweet_dialogue(text, "entrance", sweet_mode, dialogue_data)
print(text)
else:
text = "You need a ticket. Buy one at the ticket booth (West)."
text = sweet_dialogue(text, "entrance", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "entrance", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Go North' (with ticket), 'Go West', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "entrance", sweet_mode, dialogue_data)
print(text)
elif location == "ticket_booth":
text = "You're at the ticket booth. Tickets are $40."
text = sweet_dialogue(text, "ticket_booth", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "ticket_booth", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Buy Ticket', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "ticket_booth", sweet_mode, dialogue_data)
print(text)
elif location == "security":
text = "You're at the security check. They're checking bags and tickets."
text = sweet_dialogue(text, "security", sweet_mode, dialogue_data)
print(text)
if has_item(inventory, "ticket"):
text = "The guard checks your ticket and lets you through to the elevator (North)."
text = sweet_dialogue(text, "security", sweet_mode, dialogue_data)
print(text)
else:
text = "You need a ticket to go through."
text = sweet_dialogue(text, "security", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "security", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Go North' (with ticket), 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "security", sweet_mode, dialogue_data)
print(text)
elif location == "elevator":
text = "You're in the elevator. The doors close."
text = sweet_dialogue(text, "elevator", sweet_mode, dialogue_data)
print(text)
time.sleep(2)
text = "Going up fast..."
text = sweet_dialogue(text, "elevator", sweet_mode, dialogue_data)
print(text)
time.sleep(3)
text = "Your ears pop."
text = sweet_dialogue(text, "elevator", sweet_mode, dialogue_data)
print(text)
time.sleep(2)
text = "Ding! LookOut level."
text = sweet_dialogue(text, "elevator", sweet_mode, dialogue_data)
print(text)
return "lookout"
elif location == "lookout":
text = "You're on the LookOut level! Great view of Toronto."
text = sweet_dialogue(text, "lookout", sweet_mode, dialogue_data)
print(text)
text = "You see the city, the lake, and Niagara Falls far away."
text = sweet_dialogue(text, "lookout", sweet_mode, dialogue_data)
print(text)
text = "Stairs to Glass Floor (Down). Info booth (East)."
text = sweet_dialogue(text, "lookout", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "lookout", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Go Down', 'Go East', 'Look Around', 'Exit', 'Restart'."
text = sweet_dialogue(text, "lookout", sweet_mode, dialogue_data)
print(text)
elif location == "glass_floor":
text = "You're on the Glass Floor! It's scary to look down."
text = sweet_dialogue(text, "glass_floor", sweet_mode, dialogue_data)
print(text)
text = "You see the ground 342 meters below."
text = sweet_dialogue(text, "glass_floor", sweet_mode, dialogue_data)
print(text)
text = "Stairs up to LookOut level. EdgeWalk sign (West)."
text = sweet_dialogue(text, "glass_floor", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "glass_floor", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Go Up', 'Go West', 'Look Down', 'Exit', 'Restart'."
text = sweet_dialogue(text, "glass_floor", sweet_mode, dialogue_data)
print(text)
elif location == "edgewalk_registration":
text = "You're at the EdgeWalk desk."
text = sweet_dialogue(text, "edgewalk_registration", sweet_mode, dialogue_data)
print(text)
if has_item(inventory, "edgewalk_ticket"):
text = "You have a ticket! The guide is preparing the gear (North)."
text = sweet_dialogue(text, "edgewalk_registration", sweet_mode, dialogue_data)
print(text)
else:
text = "You need a ticket for EdgeWalk. It's $195. Buy one here."
text = sweet_dialogue(text, "edgewalk_registration", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "edgewalk_registration", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Buy Ticket', 'Go North' (with ticket), 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "edgewalk_registration", sweet_mode, dialogue_data)
print(text)
elif location == "edgewalk_preparation":
text = "You're in the EdgeWalk prep area. The guide helps you put on a harness."
text = sweet_dialogue(text, "edgewalk_preparation", sweet_mode, dialogue_data)
print(text)
text = "You're excited and nervous."
text = sweet_dialogue(text, "edgewalk_preparation", sweet_mode, dialogue_data)
print(text)
time.sleep(5)
text = "The guide checks your harness. Thumbs up!"
text = sweet_dialogue(text, "edgewalk_preparation", sweet_mode, dialogue_data)
print(text)
return "edgewalk"
elif location == "edgewalk":
text = "You're outside on the EdgeWalk! Wind is blowing. You're walking around the CN Tower!"
text = sweet_dialogue(text, "edgewalk", sweet_mode, dialogue_data)
print(text)
text = "It's the most exciting thing ever!"
text = sweet_dialogue(text, "edgewalk", sweet_mode, dialogue_data)
print(text)
text = "Congrats! You did the EdgeWalk! (Win)"
text = sweet_dialogue(text, "edgewalk", sweet_mode, dialogue_data)
print(text)
return "exit"
elif location == "gift_shop":
text = "You're in the gift shop. They have souvenirs, postcards, and CN Tower stuff."
text = sweet_dialogue(text, "gift_shop", sweet_mode, dialogue_data)
print(text)
if not has_item(inventory, "mask"):
text = "You see a disguise kit for $20."
text = sweet_dialogue(text, "gift_shop", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "gift_shop", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Buy Postcards', 'Buy Souvenir', 'Buy Mask' (with enough money), 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "gift_shop", sweet_mode, dialogue_data)
print(text)
elif location == "information_booth":
text = "You're at the info booth. Brochures about the CN Tower are here."
text = sweet_dialogue(text, "information_booth", sweet_mode, dialogue_data)
print(text)
text = "A staff member is answering questions."
text = sweet_dialogue(text, "information_booth", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "information_booth", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Ask About History', 'Ask About Building', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "information_booth", sweet_mode, dialogue_data)
print(text)
elif location == "worker":
text = "You go to the worker. He looks tired."
text = sweet_dialogue(text, "worker", sweet_mode, dialogue_data)
print(text)
text = '"Hey, can you help me? I need to move these boxes to the storage room."'
text = sweet_dialogue(text, "worker", sweet_mode, dialogue_data)
print(text)
time.sleep(2)
text = "You start helping."
text = sweet_dialogue(text, "worker", sweet_mode, dialogue_data)
print(text)
for i in range(1, 5):
text = f"You carry box {i} to the storage room..."
text = sweet_dialogue(text, "worker", sweet_mode, dialogue_data)
print(text)
time.sleep(2)
text = "You pick up the 5th box. It's open a bit."
text = sweet_dialogue(text, "worker", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "worker", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Look Inside', 'Continue', 'Exit', 'Restart'."
text = sweet_dialogue(text, "worker", sweet_mode, dialogue_data)
print(text)
elif location == "open_box":
text = "You look inside. You see money, a book, and a mask."
text = sweet_dialogue(text, "open_box", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "open_box", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Take Nothing', 'Take Money', 'Take Book', 'Take Mask', 'Exit', 'Restart'."
text = sweet_dialogue(text, "open_box", sweet_mode, dialogue_data)
print(text)
elif location == "caught_stealing":
text = "The worker sees you!"
text = sweet_dialogue(text, "caught_stealing", sweet_mode, dialogue_data)
print(text)
text = 'Worker: "Hey! What are you doing?!"'
text = sweet_dialogue(text, "caught_stealing", sweet_mode, dialogue_data)
print(text)
time.sleep(2)
text = "He calls security. You're taken to the police."
text = sweet_dialogue(text, "caught_stealing", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "caught_stealing", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Tell Truth', 'Bribe', 'Lie', 'Exit', 'Restart'."
text = sweet_dialogue(text, "caught_stealing", sweet_mode, dialogue_data)
print(text)
elif location == "police_station":
text = "You're at the police station. The officer is asking you questions."
text = sweet_dialogue(text, "police_station", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "police_station", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Tell Truth', 'Bribe', 'Lie', 'Exit', 'Restart'."
text = sweet_dialogue(text, "police_station", sweet_mode, dialogue_data)
print(text)
elif location == "storage_room":
text = "You're in the storage room with the worker."
text = sweet_dialogue(text, "storage_room", sweet_mode, dialogue_data)
print(text)
text = 'Worker: "Thanks a lot! Here\'s $20."'
text = sweet_dialogue(text, "storage_room", sweet_mode, dialogue_data)
print(text)
inventory["money"] += 20
add_item(inventory, "worker_task")
text = "You got $20."
text = sweet_dialogue(text, "storage_room", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "storage_room", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "storage_room", sweet_mode, dialogue_data)
print(text)
elif location == "just_a_chill_guy":
text = "You see Just a Chill Guy. He's laughing, looking at a corner."
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
if has_item(inventory, "mask") and has_item(inventory, "bible"):
text = "You have a mask and a Bible. You're ready to scare Alex Rivers!"
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Go West', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
elif has_item(inventory, "bible") and not has_item(inventory, "mask"):
text = 'Just a Chill Guy: "Now that the quadrobists ran away, you can scare Alex using the mask."'
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Use Mask', 'Go Forward', 'Ask About Corner', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
elif inventory.get("used_bible", False):
text = 'Just a Chill Guy: "You scared the quadrobists good, now you can scare Alex."'
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Use Mask', 'Go Forward', 'Ask About Corner', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
else:
text = "What do you want to do?"
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Use Mask', 'Use Bible', 'Go Forward', 'Ask About Corner', 'Back', 'Exit', 'Restart'."
text = sweet_dialogue(text, "just_a_chill_guy", sweet_mode, dialogue_data)
print(text)
elif location == "corner":
if has_item(inventory, "mask") and inventory.get("used_mask", False):
text = "You use your mask and peek around the corner. You see quadrobists practicing."
text = sweet_dialogue(text, "corner", sweet_mode, dialogue_data)
print(text)
text = "They don't see you. You go back to Just a Chill Guy."
text = sweet_dialogue(text, "corner", sweet_mode, dialogue_data)
print(text)
return "just_a_chill_guy"
else:
text = "You go to the corner, and quadrobists see you!"
text = sweet_dialogue(text, "corner", sweet_mode, dialogue_data)
print(text)
text = "They make you join their quadrobics training."
text = sweet_dialogue(text, "corner", sweet_mode, dialogue_data)
print(text)
time.sleep(3)
text = "Now you're a quadrobist. You must scare Alex Rivers."
text = sweet_dialogue(text, "corner", sweet_mode, dialogue_data)
print(text)
return "quadrobics_base"
elif location == "quadrobics_base":
text = "You move like a quadrobist. Alex is West."
text = sweet_dialogue(text, "quadrobics_base", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Go West', 'Exit', 'Restart'."
text = sweet_dialogue(text, "quadrobics_base", sweet_mode, dialogue_data)
print(text)
elif location == "scare_alex":
text = "You successfully scared Alex Rivers using the mask and the Bible!"
text = sweet_dialogue(text, "scare_alex", sweet_mode, dialogue_data)
print(text)
text = "Alex runs away, dropping their phone. You see your chance!"
text = sweet_dialogue(text, "scare_alex", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Take Phone', 'Leave Phone', 'Exit', 'Restart'"
text = sweet_dialogue(text, "scare_alex", sweet_mode, dialogue_data)
print(text)
elif location == "phone_found":
text = "You take the phone and run to the edge of the roof. There are no obstacles in front of you."
text = sweet_dialogue(text, "phone_found", sweet_mode, dialogue_data)
print(text)
text = "What do you want to do?"
text = sweet_dialogue(text, "phone_found", sweet_mode, dialogue_data)
print(text)
text = "Hints: 'Jump', 'Go Back' to the Glass Floor, 'Exit', 'Restart'"
text = sweet_dialogue(text, "phone_found", sweet_mode, dialogue_data)
print(text)
elif location == "roof":
text = "You jumped from the roof. The last thing you see is blue sky"
text = sweet_dialogue(text, "roof", sweet_mode, dialogue_data)
print(text)
return "exit"
else:
print("Invalid location.")
print("---")
return location # Return the current location
def process_command(command, current_location, inventory, sweet_mode, dialogue_data, is_restricted):
"""Processes the player's command and updates the location and inventory.
Args:
command (str): The player's command.
current_location (str): The current location in the game.
inventory (dict): The player's inventory.
sweet_mode (bool): Whether sweet+ mode is enabled.
dialogue_data (dict): The loaded dialogue data.
is_restricted (bool): Whether the user is in a restricted country.
Returns:
tuple: The new location, updated inventory, and sweet_mode.
"""
new_location = current_location
if current_location == "base":
if command == "go north":
new_location = "entrance"
elif command == "go east":
new_location = "gift_shop"
elif command == "go west":
if not inventory.get("met_alex", False):
new_location = "alex_rivers"
else:
new_location = "Patrick"
elif command == "go south" and "worker_task" not in inventory and not inventory.get("met_Patrick", False):
new_location = "worker"
elif command == "look around":
text = "You see people taking pictures and the tower."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
elif command == "help":
text = "Use 'Go' + direction (North, South, East, West) to move."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
text = "Use 'Look Around' to see more."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
text = "Interact with things using commands like 'Buy Ticket', 'Ask About History'."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
text = "'Inventory' shows your items and money."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
text = "'Exit' - quit game, 'Restart' - start new game"
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
elif command == "inventory":
display_inventory(inventory)
elif command == "exit":
new_location = "exit"
elif command == "restart":
new_location = "restart"
elif command == "debug":
new_location, inventory, sweet_mode = display_debug_menu(inventory, sweet_mode, is_restricted)
if new_location:
return new_location, inventory, sweet_mode
elif command == "save":
save_game(current_location, inventory)
elif command == "load":
new_location, inventory = load_game()
else:
text = "Invalid command. Check the hints."
text = sweet_dialogue(text, "base", sweet_mode, dialogue_data)
print(text)
elif current_location == "alex_rivers":
if inventory.get("met_alex", False):
if command == "compliment alex":
text = 'Alex: "You\'re too kind! It\'s always nice to meet a fan."'
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
text = "Alex doesn't give you anything"
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
new_location = "base"
elif command == "ignore":
text = "You ignore Alex and continue."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
new_location = "base"
elif command == "exit":
new_location = "exit"
elif command == "restart":
new_location = "restart"
else:
text = "Invalid command. Check the hints."
text = sweet_dialogue(text, "alex_rivers", sweet_mode, dialogue_data)
print(text)
else:
new_location = "base"
elif current_location == "Patrick":
if command == "join":
text = "You join Patrick's quadrobics club."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
text = "You spend a year practicing, forgetting about the CN Tower."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
text = "One day, you're mistaken for a stray cat and taken to a shelter."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
text = "You're adopted and live a comfy but meaningless life."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
text = "You become useless. (Bad Ending)"
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
new_location = "exit"
elif command == "decline":
text = "You decline Patrick's offer."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
new_location = "base"
elif command == "back":
new_location = "base"
elif command == "exit":
new_location = "exit"
elif command == "restart":
new_location = "restart"
else:
text = "Invalid command. Check the hints."
text = sweet_dialogue(text, "Patrick", sweet_mode, dialogue_data)
print(text)
elif current_location == "entrance":
if command == "go north" and "ticket" in inventory:
new_location = "security"
elif command == "go west":
new_location = "ticket_booth"
elif command == "back":
new_location = "base"
elif command == "inventory":
display_inventory(inventory)
elif command == "exit":
new_location = "exit"
elif command == "restart":
new_location = "restart"
else:
text = "Invalid command or no ticket. Check the hints."
text = sweet_dialogue(text, "entrance", sweet_mode, dialogue_data)
print(text)
elif current_location == "ticket_booth":
if command == "buy ticket":
if "money" in inventory and inventory["money"] >= 40:
inventory["money"] -= 40
inventory["ticket"] = True
text = "You bought a ticket for $40."
text = sweet_dialogue(text, "ticket_booth", sweet_mode, dialogue_data)
print(text)
else:
text = "Not enough money."
text = sweet_dialogue(text, "ticket_booth", sweet_mode, dialogue_data)
print(text)
elif command == "back":
new_location = "entrance"
elif command == "inventory":
display_inventory(inventory)
elif command == "exit":
new_location = "exit"
elif command == "restart":
new_location = "restart"
else:
text = "Invalid command. Check the hints."
text = sweet_dialogue(text, "ticket_booth", sweet_mode, dialogue_data)
print(text)
elif current_location == "security":
if command == "go north" and "ticket" in inventory:
new_location = "elevator"
elif command == "back":
new_location = "entrance"