Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d2e84b

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 047911e according to the output from Autopep8. Details: None
1 parent f1d9e01 commit 5d2e84b

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

‎Haunted House Text Adventure Game/haunted_house_game.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import time
22
import random
33

4+
45
def print_slow(text):
56
for char in text:
67
print(char, end='', flush=True)
78
time.sleep(0.03)
89
print()
910

11+
1012
def intro():
1113
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.")
1418
print_slow("You decide to enter the house.")
1519

20+
1621
def show_inventory(inventory):
1722
print_slow("Inventory:")
1823
if not inventory:
@@ -21,6 +26,7 @@ def show_inventory(inventory):
2126
for item in inventory:
2227
print_slow(f"- {item}")
2328

29+
2430
def ask_riddle():
2531
riddles = [
2632
{
@@ -36,7 +42,7 @@ def ask_riddle():
3642
'answer': "a piano"
3743
}
3844
]
39-
45+
4046
riddle = random.choice(riddles)
4147
print_slow(riddle['question'])
4248
attempts = 3
@@ -48,13 +54,17 @@ def ask_riddle():
4854
else:
4955
attempts -= 1
5056
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.")
5259
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.")
5564
main()
5665
return False
5766

67+
5868
def left_door(inventory):
5969
print_slow("You enter a dusty library with cobwebs everywhere.")
6070
print_slow("You notice a book lying on the table.")
@@ -74,38 +84,46 @@ def left_door(inventory):
7484
left_door(inventory)
7585
choose_path(inventory)
7686

87+
7788
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']
7991
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.")
8295
print_slow("You realize the doll is playing hide-and-seek with you!")
8396
print_slow("You have 3 attempts to find where the doll is hiding.")
84-
97+
8598
for attempt in range(3):
8699
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")
88102
guess = input("Enter your choice: ").lower()
89-
103+
90104
if guess == hidden_spot:
91105
print_slow("Congratulations! You found the doll!")
92106
print_slow("The doll rewards you with a key.")
93107
return True
94108
else:
95109
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.")
98113
print_slow("You leave the room empty-handed.")
99114
return False
100115

116+
101117
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.")
103120
print_slow("The doll suddenly comes to life and speaks to you.")
104121
print_slow("It asks you to play a game of hide-and-seek.")
105-
122+
106123
if hide_and_seek():
107124
inventory.append('Key')
108125

126+
109127
def choose_path(inventory):
110128
print_slow("You step into the entrance hall and see two doors.")
111129
print_slow("Do you want to go through the 'left' door or the 'right' door?")
@@ -118,11 +136,13 @@ def choose_path(inventory):
118136
print_slow("Invalid choice. Please enter 'left' or 'right'.")
119137
choose_path(inventory)
120138

139+
121140
def main():
122141
intro()
123142
inventory = []
124143
choose_path(inventory)
125144
show_inventory(inventory)
126145

146+
127147
if __name__ == "__main__":
128148
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /