|
1 | 1 | import time
|
2 | 2 | import random
|
3 | 3 |
|
| 4 | + |
4 | 5 | def print_slow(text):
|
5 | 6 | for char in text:
|
6 | 7 | print(char, end='', flush=True)
|
7 | 8 | time.sleep(0.05)
|
8 | 9 | print()
|
9 | 10 |
|
| 11 | + |
10 | 12 | def get_choice(prompt, options):
|
11 | 13 | while True:
|
12 | 14 | print(prompt)
|
13 | 15 | for i, option in enumerate(options, 1):
|
14 | 16 | print(f"{i}. {option}")
|
15 | 17 | try:
|
16 |
| - choice = int(input("Enter your choice (1-{}): ".format(len(options)))) |
| 18 | + choice = int( |
| 19 | + input("Enter your choice (1-{}): ".format(len(options)))) |
17 | 20 | if 1 <= choice <= len(options):
|
18 | 21 | return choice
|
19 | 22 | else:
|
20 | 23 | print("Invalid input. Please choose a valid option.")
|
21 | 24 | except ValueError:
|
22 | 25 | print("Invalid input. Please enter a number.")
|
23 | 26 |
|
| 27 | + |
24 | 28 | def time_travel_adventure():
|
25 | 29 | print_slow("Welcome to the Time Travel Adventure!\n")
|
26 | 30 | print_slow("You find a mysterious time machine and decide to give it a try.")
|
27 |
| - |
| 31 | + |
28 | 32 | inventory = []
|
29 | 33 | health_points = 100
|
30 |
| - |
| 34 | + |
31 | 35 | # Starting point - Present
|
32 | 36 | print_slow("\nYou are in the present time.")
|
33 |
| - choice = get_choice("Where would you like to travel?", ["Go to the past", "Go to the future", "Go to the Medieval Era", "Go to the Space Age"]) |
34 |
| - |
| 37 | + choice = get_choice("Where would you like to travel?", [ |
| 38 | + "Go to the past", "Go to the future", "Go to the Medieval Era", "Go to the Space Age"]) |
| 39 | + |
35 | 40 | if choice == 1:
|
36 | 41 | print_slow("\nYou traveled to the past.")
|
37 | 42 | # Past storyline and choices here
|
38 | 43 | print_slow("You encountered dinosaurs in the past.")
|
39 |
| - choice = get_choice("What do you do?", ["Try to befriend them", "Run away"]) |
| 44 | + choice = get_choice("What do you do?", [ |
| 45 | + "Try to befriend them", "Run away"]) |
40 | 46 | if choice == 1:
|
41 |
| - print_slow("You manage to befriend a baby dinosaur. It's a heartwarming moment!") |
| 47 | + print_slow( |
| 48 | + "You manage to befriend a baby dinosaur. It's a heartwarming moment!") |
42 | 49 | inventory.append("Dinosaur Egg")
|
43 | 50 | else:
|
44 |
| - print_slow("You ran away from the dinosaurs and found yourself back in the present.") |
| 51 | + print_slow( |
| 52 | + "You ran away from the dinosaurs and found yourself back in the present.") |
45 | 53 | elif choice == 2:
|
46 | 54 | print_slow("\nYou traveled to the future.")
|
47 | 55 | # Future storyline and choices here
|
48 | 56 | print_slow("You arrived in a futuristic city.")
|
49 |
| - choice = get_choice("What do you do?", ["Explore the city", "Seek help from locals"]) |
| 57 | + choice = get_choice("What do you do?", [ |
| 58 | + "Explore the city", "Seek help from locals"]) |
50 | 59 | if choice == 1:
|
51 |
| - print_slow("You explored the city and had a fascinating experience in the future.") |
| 60 | + print_slow( |
| 61 | + "You explored the city and had a fascinating experience in the future.") |
52 | 62 | health_points -= 20
|
53 | 63 | else:
|
54 |
| - print_slow("The locals are friendly and offer you a tour of their advanced technology.") |
| 64 | + print_slow( |
| 65 | + "The locals are friendly and offer you a tour of their advanced technology.") |
55 | 66 | inventory.append("Futuristic Device")
|
56 | 67 | elif choice == 3:
|
57 | 68 | print_slow("\nYou traveled to the Medieval Era.")
|
58 | 69 | # Medieval storyline and choices here
|
59 | 70 | print_slow("You find yourself in a medieval kingdom.")
|
60 |
| - choice = get_choice("What do you do?", ["Attend a royal feast", "Help a poor villager"]) |
| 71 | + choice = get_choice("What do you do?", [ |
| 72 | + "Attend a royal feast", "Help a poor villager"]) |
61 | 73 | if choice == 1:
|
62 |
| - print_slow("You attended a grand feast at the castle. The king was impressed by your presence.") |
| 74 | + print_slow( |
| 75 | + "You attended a grand feast at the castle. The king was impressed by your presence.") |
63 | 76 | inventory.append("Royal Medal")
|
64 | 77 | else:
|
65 |
| - print_slow("You helped the villager, who turned out to be a powerful sorcerer. He grants you a magical amulet.") |
| 78 | + print_slow( |
| 79 | + "You helped the villager, who turned out to be a powerful sorcerer. He grants you a magical amulet.") |
66 | 80 | inventory.append("Amulet of Power")
|
67 | 81 | else:
|
68 | 82 | print_slow("\nYou traveled to the Space Age.")
|
69 | 83 | # Space Age storyline and choices here
|
70 | 84 | print_slow("You are on a space station orbiting a distant planet.")
|
71 |
| - choice = get_choice("What do you do?", ["Investigate the planet", "Repair the space station"]) |
| 85 | + choice = get_choice("What do you do?", [ |
| 86 | + "Investigate the planet", "Repair the space station"]) |
72 | 87 | if choice == 1:
|
73 |
| - print_slow("You embarked on a planetary exploration mission and made significant scientific discoveries.") |
| 88 | + print_slow( |
| 89 | + "You embarked on a planetary exploration mission and made significant scientific discoveries.") |
74 | 90 | inventory.append("Alien Artifact")
|
75 | 91 | else:
|
76 |
| - print_slow("You successfully repaired the space station and gained the respect of the space crew.") |
| 92 | + print_slow( |
| 93 | + "You successfully repaired the space station and gained the respect of the space crew.") |
77 | 94 | inventory.append("Space Suit")
|
78 |
| - |
| 95 | + |
79 | 96 | if health_points <= 0:
|
80 | 97 | print_slow("\nYour health is too low to continue the journey. Game Over!")
|
81 | 98 | else:
|
82 | 99 | # Random event during time travel
|
83 | 100 | if random.random() < 0.3:
|
84 |
| - print_slow("\nDuring your time travel, you encounter a time vortex!") |
| 101 | + print_slow( |
| 102 | + "\nDuring your time travel, you encounter a time vortex!") |
85 | 103 | print_slow("You got disoriented but managed to find your way back.")
|
86 | 104 | health_points -= 10
|
87 |
| - |
| 105 | + |
88 | 106 | print_slow("\nYou are back in the present time.")
|
89 |
| - choice = get_choice("What would you like to do?", ["End the game", "Continue the adventure"]) |
| 107 | + choice = get_choice("What would you like to do?", [ |
| 108 | + "End the game", "Continue the adventure"]) |
90 | 109 | if choice == 1:
|
91 | 110 | print_slow("\nThanks for playing the Time Travel Adventure!")
|
92 | 111 | else:
|
93 | 112 | print_slow("You decide to embark on another time travel adventure!")
|
94 | 113 | time_travel_adventure()
|
95 | 114 |
|
| 115 | + |
96 | 116 | if __name__ == "__main__":
|
97 | 117 | time_travel_adventure()
|
0 commit comments