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