Skip to content

format code with autopep8 #2814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions Haunted House Text Adventure Game/haunted_house_game.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import time
import random


def print_slow(text):
for char in text:
print(char, end='', flush=True)
time.sleep(0.03)
print()


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


def show_inventory(inventory):
print_slow("Inventory:")
if not inventory:
Expand All @@ -21,6 +26,7 @@ def show_inventory(inventory):
for item in inventory:
print_slow(f"- {item}")


def ask_riddle():
riddles = [
{
Expand All @@ -36,7 +42,7 @@ def ask_riddle():
'answer': "a piano"
}
]

riddle = random.choice(riddles)
print_slow(riddle['question'])
attempts = 3
Expand All @@ -48,13 +54,17 @@ def ask_riddle():
else:
attempts -= 1
if attempts > 0:
print_slow(f"Incorrect! You have {attempts} {'attempts' if attempts > 1 else 'attempt'} left.")
print_slow(
f"Incorrect! You have {attempts} {'attempts' if attempts > 1 else 'attempt'} left.")
else:
print_slow("Incorrect! The ghost becomes angry and attacks you.")
print_slow("You wake up outside the haunted house with all your progress reset.")
print_slow(
"Incorrect! The ghost becomes angry and attacks you.")
print_slow(
"You wake up outside the haunted house with all your progress reset.")
main()
return False


def left_door(inventory):
print_slow("You enter a dusty library with cobwebs everywhere.")
print_slow("You notice a book lying on the table.")
Expand All @@ -74,38 +84,46 @@ def left_door(inventory):
left_door(inventory)
choose_path(inventory)


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

print_slow("The creepy doll disappears, and you hear eerie giggles echoing in the room.")

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

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

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

print_slow("You couldn't find the doll, and it reappears with a mischievous grin.")

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


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

if hide_and_seek():
inventory.append('Key')


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


def main():
intro()
inventory = []
choose_path(inventory)
show_inventory(inventory)


if __name__ == "__main__":
main()