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.03 )
8
9
print ()
9
10
11
+
10
12
def intro ():
11
13
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 (
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." )
14
18
print_slow ("You decide to enter the house." )
15
19
20
+
16
21
def show_inventory (inventory ):
17
22
print_slow ("Inventory:" )
18
23
if not inventory :
@@ -21,6 +26,7 @@ def show_inventory(inventory):
21
26
for item in inventory :
22
27
print_slow (f"- { item } " )
23
28
29
+
24
30
def ask_riddle ():
25
31
riddles = [
26
32
{
@@ -36,7 +42,7 @@ def ask_riddle():
36
42
'answer' : "a piano"
37
43
}
38
44
]
39
-
45
+
40
46
riddle = random .choice (riddles )
41
47
print_slow (riddle ['question' ])
42
48
attempts = 3
@@ -48,13 +54,17 @@ def ask_riddle():
48
54
else :
49
55
attempts -= 1
50
56
if attempts > 0 :
51
- print_slow (f"Incorrect! You have { attempts } { 'attempts' if attempts > 1 else 'attempt' } left." )
57
+ print_slow (
58
+ f"Incorrect! You have { attempts } { 'attempts' if attempts > 1 else 'attempt' } left." )
52
59
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." )
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." )
55
64
main ()
56
65
return False
57
66
67
+
58
68
def left_door (inventory ):
59
69
print_slow ("You enter a dusty library with cobwebs everywhere." )
60
70
print_slow ("You notice a book lying on the table." )
@@ -74,38 +84,46 @@ def left_door(inventory):
74
84
left_door (inventory )
75
85
choose_path (inventory )
76
86
87
+
77
88
def hide_and_seek ():
78
- hiding_spots = ['under the bed' , 'behind the curtains' , 'inside the wardrobe' , 'under the table' ]
89
+ hiding_spots = ['under the bed' , 'behind the curtains' ,
90
+ 'inside the wardrobe' , 'under the table' ]
79
91
hidden_spot = random .choice (hiding_spots )
80
-
81
- print_slow ("The creepy doll disappears, and you hear eerie giggles echoing in the room." )
92
+
93
+ print_slow (
94
+ "The creepy doll disappears, and you hear eerie giggles echoing in the room." )
82
95
print_slow ("You realize the doll is playing hide-and-seek with you!" )
83
96
print_slow ("You have 3 attempts to find where the doll is hiding." )
84
-
97
+
85
98
for attempt in range (3 ):
86
99
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" )
100
+ print_slow (
101
+ "Choose from: under the bed, behind the curtains, inside the wardrobe, under the table" )
88
102
guess = input ("Enter your choice: " ).lower ()
89
-
103
+
90
104
if guess == hidden_spot :
91
105
print_slow ("Congratulations! You found the doll!" )
92
106
print_slow ("The doll rewards you with a key." )
93
107
return True
94
108
else :
95
109
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." )
110
+
111
+ print_slow (
112
+ "You couldn't find the doll, and it reappears with a mischievous grin." )
98
113
print_slow ("You leave the room empty-handed." )
99
114
return False
100
115
116
+
101
117
def right_door (inventory ):
102
- print_slow ("You enter a dimly lit room with a creepy doll sitting in a rocking chair." )
118
+ print_slow (
119
+ "You enter a dimly lit room with a creepy doll sitting in a rocking chair." )
103
120
print_slow ("The doll suddenly comes to life and speaks to you." )
104
121
print_slow ("It asks you to play a game of hide-and-seek." )
105
-
122
+
106
123
if hide_and_seek ():
107
124
inventory .append ('Key' )
108
125
126
+
109
127
def choose_path (inventory ):
110
128
print_slow ("You step into the entrance hall and see two doors." )
111
129
print_slow ("Do you want to go through the 'left' door or the 'right' door?" )
@@ -118,11 +136,13 @@ def choose_path(inventory):
118
136
print_slow ("Invalid choice. Please enter 'left' or 'right'." )
119
137
choose_path (inventory )
120
138
139
+
121
140
def main ():
122
141
intro ()
123
142
inventory = []
124
143
choose_path (inventory )
125
144
show_inventory (inventory )
126
145
146
+
127
147
if __name__ == "__main__" :
128
148
main ()
0 commit comments