|
| 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.03) |
| 8 | + print() |
| 9 | + |
| 10 | +def intro(): |
| 11 | + print_slow("Welcome to the Haunted House!") |
| 12 | + print_slow("You find yourself standing in front of a spooky old house on a dark, stormy night.") |
| 13 | + print_slow("Legend has it that the house is haunted, but you are determined to uncover the mystery.") |
| 14 | + print_slow("You decide to enter the house.") |
| 15 | + |
| 16 | +def show_inventory(inventory): |
| 17 | + print_slow("Inventory:") |
| 18 | + if not inventory: |
| 19 | + print_slow("Your inventory is empty.") |
| 20 | + else: |
| 21 | + for item in inventory: |
| 22 | + print_slow(f"- {item}") |
| 23 | + |
| 24 | +def ask_riddle(): |
| 25 | + riddles = [ |
| 26 | + { |
| 27 | + 'question': "I speak without a mouth and hear without ears. I have no body, but I come alive with the wind. What am I?", |
| 28 | + 'answer': "an echo" |
| 29 | + }, |
| 30 | + { |
| 31 | + 'question': "The more you take, the more you leave behind. What am I?", |
| 32 | + 'answer': "footsteps" |
| 33 | + }, |
| 34 | + { |
| 35 | + 'question': "What has keys but can't open locks?", |
| 36 | + 'answer': "a piano" |
| 37 | + } |
| 38 | + ] |
| 39 | + |
| 40 | + riddle = random.choice(riddles) |
| 41 | + print_slow(riddle['question']) |
| 42 | + attempts = 3 |
| 43 | + while attempts > 0: |
| 44 | + answer = input("Enter your answer: ").lower() |
| 45 | + if answer == riddle['answer']: |
| 46 | + print_slow("Correct! The ghost is pleased and vanishes.") |
| 47 | + return True |
| 48 | + else: |
| 49 | + attempts -= 1 |
| 50 | + if attempts > 0: |
| 51 | + print_slow(f"Incorrect! You have {attempts} {'attempts' if attempts > 1 else 'attempt'} left.") |
| 52 | + else: |
| 53 | + print_slow("Incorrect! The ghost becomes angry and attacks you.") |
| 54 | + print_slow("You wake up outside the haunted house with all your progress reset.") |
| 55 | + main() |
| 56 | + return False |
| 57 | + |
| 58 | +def left_door(inventory): |
| 59 | + print_slow("You enter a dusty library with cobwebs everywhere.") |
| 60 | + print_slow("You notice a book lying on the table.") |
| 61 | + print_slow("Do you want to read the book? (yes/no)") |
| 62 | + choice = input("Enter your choice: ").lower() |
| 63 | + if choice == 'yes': |
| 64 | + print_slow("You open the book and a ghostly figure appears!") |
| 65 | + print_slow("The ghost challenges you to a riddle.") |
| 66 | + if ask_riddle(): |
| 67 | + inventory.append('Book') |
| 68 | + else: |
| 69 | + return |
| 70 | + elif choice == 'no': |
| 71 | + print_slow("You decide not to read the book and leave the library.") |
| 72 | + else: |
| 73 | + print_slow("Invalid choice. Please enter 'yes' or 'no'.") |
| 74 | + left_door(inventory) |
| 75 | + choose_path(inventory) |
| 76 | + |
| 77 | +def hide_and_seek(): |
| 78 | + hiding_spots = ['under the bed', 'behind the curtains', 'inside the wardrobe', 'under the table'] |
| 79 | + hidden_spot = random.choice(hiding_spots) |
| 80 | + |
| 81 | + print_slow("The creepy doll disappears, and you hear eerie giggles echoing in the room.") |
| 82 | + print_slow("You realize the doll is playing hide-and-seek with you!") |
| 83 | + print_slow("You have 3 attempts to find where the doll is hiding.") |
| 84 | + |
| 85 | + for attempt in range(3): |
| 86 | + print_slow(f"Attempt {attempt + 1}: Where do you want to search?") |
| 87 | + print_slow("Choose from: under the bed, behind the curtains, inside the wardrobe, under the table") |
| 88 | + guess = input("Enter your choice: ").lower() |
| 89 | + |
| 90 | + if guess == hidden_spot: |
| 91 | + print_slow("Congratulations! You found the doll!") |
| 92 | + print_slow("The doll rewards you with a key.") |
| 93 | + return True |
| 94 | + else: |
| 95 | + print_slow("Nope, the doll isn't there.") |
| 96 | + |
| 97 | + print_slow("You couldn't find the doll, and it reappears with a mischievous grin.") |
| 98 | + print_slow("You leave the room empty-handed.") |
| 99 | + return False |
| 100 | + |
| 101 | +def right_door(inventory): |
| 102 | + print_slow("You enter a dimly lit room with a creepy doll sitting in a rocking chair.") |
| 103 | + print_slow("The doll suddenly comes to life and speaks to you.") |
| 104 | + print_slow("It asks you to play a game of hide-and-seek.") |
| 105 | + |
| 106 | + if hide_and_seek(): |
| 107 | + inventory.append('Key') |
| 108 | + |
| 109 | +def choose_path(inventory): |
| 110 | + print_slow("You step into the entrance hall and see two doors.") |
| 111 | + print_slow("Do you want to go through the 'left' door or the 'right' door?") |
| 112 | + choice = input("Enter your choice: ").lower() |
| 113 | + if choice == 'left': |
| 114 | + left_door(inventory) |
| 115 | + elif choice == 'right': |
| 116 | + right_door(inventory) |
| 117 | + else: |
| 118 | + print_slow("Invalid choice. Please enter 'left' or 'right'.") |
| 119 | + choose_path(inventory) |
| 120 | + |
| 121 | +def main(): |
| 122 | + intro() |
| 123 | + inventory = [] |
| 124 | + choose_path(inventory) |
| 125 | + show_inventory(inventory) |
| 126 | + |
| 127 | +if __name__ == "__main__": |
| 128 | + main() |
0 commit comments