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