Skip to content

Commit 047911e

Browse files
Merge pull request #2656 from andoriyaprashant/branch30
Haunted House Text Adventure Game Script Added
2 parents 3cdc106 + 01939ba commit 047911e

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Haunted House Text Adventure Game
2+
3+
## Overview
4+
5+
Welcome to the Haunted House Text Adventure Game! This is a text-based adventure game set in a spooky old house. The player will navigate through different rooms, solve puzzles, interact with creepy characters, and uncover the mystery of the haunted house.
6+
7+
## How to Play
8+
9+
1. Make sure you have Python 3 installed on your computer.
10+
2. Download the 'haunted_house_game.py' file to your local machine.
11+
3. Open a terminal or command prompt and navigate to the directory where the file is located.
12+
4. Run the game by typing the following command:
13+
14+
```bash
15+
python haunted_house_game.py
16+
```
17+
18+
5. Follow the on-screen instructions to make choices and progress through the game.
19+
6. Interact with the haunted house, solve riddles, and play mini-games to collect items and unravel the mysteries.
20+
7. Use the 'yes' or 'no' responses to make choices throughout the game.
21+
22+
## Features
23+
24+
1. Text-based Adventure: The game is entirely text-based, creating an immersive and interactive experience.
25+
2. Multiple Endings: The outcome of the game is influenced by the player's choices, leading to different endings.
26+
3. Inventory System: Collect items during the game and use them to solve puzzles and progress.
27+
4. NPC Interaction: Meet spooky characters in different rooms and interact with them using dialogues.
28+
5. Puzzle Challenges: Solve riddles and play mini-games to advance in the story.
29+
6. Timer and Score: Experience a sense of urgency with a timer and track your score based on your progress.
30+
7. Save/Load Game: Save your progress and continue the adventure from where you left off.
31+
32+
## Contributions
33+
34+
Contributions to this game are welcome! If you have any creative ideas or want to enhance the gameplay, feel free to submit a pull request.
35+
36+
Enjoy the adventure and have fun exploring the haunted house!
37+
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import time
2+
import random
3+
4+
def print_slow(text):
5+
for char in text:
6+
print(char, end='', flush=True)
7+
time.sleep(0.03)
8+
print()
9+
10+
def intro():
11+
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("You decide to enter the house.")
15+
16+
def show_inventory(inventory):
17+
print_slow("Inventory:")
18+
if not inventory:
19+
print_slow("Your inventory is empty.")
20+
else:
21+
for item in inventory:
22+
print_slow(f"- {item}")
23+
24+
def ask_riddle():
25+
riddles = [
26+
{
27+
'question': "I speak without a mouth and hear without ears. I have no body, but I come alive with the wind. What am I?",
28+
'answer': "an echo"
29+
},
30+
{
31+
'question': "The more you take, the more you leave behind. What am I?",
32+
'answer': "footsteps"
33+
},
34+
{
35+
'question': "What has keys but can't open locks?",
36+
'answer': "a piano"
37+
}
38+
]
39+
40+
riddle = random.choice(riddles)
41+
print_slow(riddle['question'])
42+
attempts = 3
43+
while attempts > 0:
44+
answer = input("Enter your answer: ").lower()
45+
if answer == riddle['answer']:
46+
print_slow("Correct! The ghost is pleased and vanishes.")
47+
return True
48+
else:
49+
attempts -= 1
50+
if attempts > 0:
51+
print_slow(f"Incorrect! You have {attempts} {'attempts' if attempts > 1 else 'attempt'} left.")
52+
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.")
55+
main()
56+
return False
57+
58+
def left_door(inventory):
59+
print_slow("You enter a dusty library with cobwebs everywhere.")
60+
print_slow("You notice a book lying on the table.")
61+
print_slow("Do you want to read the book? (yes/no)")
62+
choice = input("Enter your choice: ").lower()
63+
if choice == 'yes':
64+
print_slow("You open the book and a ghostly figure appears!")
65+
print_slow("The ghost challenges you to a riddle.")
66+
if ask_riddle():
67+
inventory.append('Book')
68+
else:
69+
return
70+
elif choice == 'no':
71+
print_slow("You decide not to read the book and leave the library.")
72+
else:
73+
print_slow("Invalid choice. Please enter 'yes' or 'no'.")
74+
left_door(inventory)
75+
choose_path(inventory)
76+
77+
def hide_and_seek():
78+
hiding_spots = ['under the bed', 'behind the curtains', 'inside the wardrobe', 'under the table']
79+
hidden_spot = random.choice(hiding_spots)
80+
81+
print_slow("The creepy doll disappears, and you hear eerie giggles echoing in the room.")
82+
print_slow("You realize the doll is playing hide-and-seek with you!")
83+
print_slow("You have 3 attempts to find where the doll is hiding.")
84+
85+
for attempt in range(3):
86+
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")
88+
guess = input("Enter your choice: ").lower()
89+
90+
if guess == hidden_spot:
91+
print_slow("Congratulations! You found the doll!")
92+
print_slow("The doll rewards you with a key.")
93+
return True
94+
else:
95+
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.")
98+
print_slow("You leave the room empty-handed.")
99+
return False
100+
101+
def right_door(inventory):
102+
print_slow("You enter a dimly lit room with a creepy doll sitting in a rocking chair.")
103+
print_slow("The doll suddenly comes to life and speaks to you.")
104+
print_slow("It asks you to play a game of hide-and-seek.")
105+
106+
if hide_and_seek():
107+
inventory.append('Key')
108+
109+
def choose_path(inventory):
110+
print_slow("You step into the entrance hall and see two doors.")
111+
print_slow("Do you want to go through the 'left' door or the 'right' door?")
112+
choice = input("Enter your choice: ").lower()
113+
if choice == 'left':
114+
left_door(inventory)
115+
elif choice == 'right':
116+
right_door(inventory)
117+
else:
118+
print_slow("Invalid choice. Please enter 'left' or 'right'.")
119+
choose_path(inventory)
120+
121+
def main():
122+
intro()
123+
inventory = []
124+
choose_path(inventory)
125+
show_inventory(inventory)
126+
127+
if __name__ == "__main__":
128+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
time
2+
random

0 commit comments

Comments
 (0)