Amazing-Python-Scripts

Форк
0
148 строк · 4.6 Кб
1
import time
2
import random
3

4

5
def print_slow(text):
6
    for char in text:
7
        print(char, end='', flush=True)
8
        time.sleep(0.03)
9
    print()
10

11

12
def intro():
13
    print_slow("Welcome to the Haunted House!")
14
    print_slow(
15
        "You find yourself standing in front of a spooky old house on a dark, stormy night.")
16
    print_slow(
17
        "Legend has it that the house is haunted, but you are determined to uncover the mystery.")
18
    print_slow("You decide to enter the house.")
19

20

21
def show_inventory(inventory):
22
    print_slow("Inventory:")
23
    if not inventory:
24
        print_slow("Your inventory is empty.")
25
    else:
26
        for item in inventory:
27
            print_slow(f"- {item}")
28

29

30
def ask_riddle():
31
    riddles = [
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

46
    riddle = random.choice(riddles)
47
    print_slow(riddle['question'])
48
    attempts = 3
49
    while attempts > 0:
50
        answer = input("Enter your answer: ").lower()
51
        if answer == riddle['answer']:
52
            print_slow("Correct! The ghost is pleased and vanishes.")
53
            return True
54
        else:
55
            attempts -= 1
56
            if attempts > 0:
57
                print_slow(
58
                    f"Incorrect! You have {attempts} {'attempts' if attempts > 1 else 'attempt'} left.")
59
            else:
60
                print_slow(
61
                    "Incorrect! The ghost becomes angry and attacks you.")
62
                print_slow(
63
                    "You wake up outside the haunted house with all your progress reset.")
64
                main()
65
                return False
66

67

68
def left_door(inventory):
69
    print_slow("You enter a dusty library with cobwebs everywhere.")
70
    print_slow("You notice a book lying on the table.")
71
    print_slow("Do you want to read the book? (yes/no)")
72
    choice = input("Enter your choice: ").lower()
73
    if choice == 'yes':
74
        print_slow("You open the book and a ghostly figure appears!")
75
        print_slow("The ghost challenges you to a riddle.")
76
        if ask_riddle():
77
            inventory.append('Book')
78
        else:
79
            return
80
    elif choice == 'no':
81
        print_slow("You decide not to read the book and leave the library.")
82
    else:
83
        print_slow("Invalid choice. Please enter 'yes' or 'no'.")
84
        left_door(inventory)
85
    choose_path(inventory)
86

87

88
def hide_and_seek():
89
    hiding_spots = ['under the bed', 'behind the curtains',
90
                    'inside the wardrobe', 'under the table']
91
    hidden_spot = random.choice(hiding_spots)
92

93
    print_slow(
94
        "The creepy doll disappears, and you hear eerie giggles echoing in the room.")
95
    print_slow("You realize the doll is playing hide-and-seek with you!")
96
    print_slow("You have 3 attempts to find where the doll is hiding.")
97

98
    for attempt in range(3):
99
        print_slow(f"Attempt {attempt + 1}: Where do you want to search?")
100
        print_slow(
101
            "Choose from: under the bed, behind the curtains, inside the wardrobe, under the table")
102
        guess = input("Enter your choice: ").lower()
103

104
        if guess == hidden_spot:
105
            print_slow("Congratulations! You found the doll!")
106
            print_slow("The doll rewards you with a key.")
107
            return True
108
        else:
109
            print_slow("Nope, the doll isn't there.")
110

111
    print_slow(
112
        "You couldn't find the doll, and it reappears with a mischievous grin.")
113
    print_slow("You leave the room empty-handed.")
114
    return False
115

116

117
def right_door(inventory):
118
    print_slow(
119
        "You enter a dimly lit room with a creepy doll sitting in a rocking chair.")
120
    print_slow("The doll suddenly comes to life and speaks to you.")
121
    print_slow("It asks you to play a game of hide-and-seek.")
122

123
    if hide_and_seek():
124
        inventory.append('Key')
125

126

127
def choose_path(inventory):
128
    print_slow("You step into the entrance hall and see two doors.")
129
    print_slow("Do you want to go through the 'left' door or the 'right' door?")
130
    choice = input("Enter your choice: ").lower()
131
    if choice == 'left':
132
        left_door(inventory)
133
    elif choice == 'right':
134
        right_door(inventory)
135
    else:
136
        print_slow("Invalid choice. Please enter 'left' or 'right'.")
137
        choose_path(inventory)
138

139

140
def main():
141
    intro()
142
    inventory = []
143
    choose_path(inventory)
144
    show_inventory(inventory)
145

146

147
if __name__ == "__main__":
148
    main()
149

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.