Repository navigation
Expand file tree
/
Copy pathtext_based_game.py
More file actions
133 lines (120 loc) · 4.05 KB
/
Copy pathtext_based_game.py
File metadata and controls
133 lines (120 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# CODE FOR TEXT BASED ADEVENTURE GAME
import time
def game_start():
print("Welcome to the Haunted House Adventure!")
time.sleep(1)
print("You find yourself standing in front of a mysterious old house.")
time.sleep(1)
print("Legend has it that the house is haunted and holds hidden treasures.")
time.sleep(1)
print("Your goal is to explore the house and find the treasure.")
time.sleep(1)
print("Let's begin!\n")
time.sleep(1)
enter_house()
def enter_house():
print("You step inside the house.")
time.sleep(1)
print("It is dark and eerie. You can see three doors ahead.")
time.sleep(1)
print("Which door will you choose?")
print("1. Door on the left")
print("2. Door in the middle")
print("3. Door on the right")
choice = input("Enter your choice (1/2/3): ")
if choice == '1':
door_left()
elif choice == '2':
door_middle()
elif choice == '3':
door_right()
else:
print("Invalid choice. Please enter 1, 2, or 3.")
enter_house()
def door_left():
print("\nYou chose the door on the left.")
time.sleep(1)
print("You enter a dusty library.")
time.sleep(1)
print("There's a bookshelf with a hidden switch.")
time.sleep(1)
print("Pull the switch or leave?")
choice = input("Enter 'pull' or 'leave': ")
if choice.lower() == 'pull':
print("\nYou pull the switch and hear a mechanical sound.")
time.sleep(1)
print("A secret passage opens!")
time.sleep(1)
explore_secret_room()
elif choice.lower() == 'leave':
print("\nYou decide to leave the library.")
time.sleep(1)
enter_house()
else:
print("Invalid choice. Please enter 'pull' or 'leave'.")
door_left()
def door_middle():
print("\nYou chose the door in the middle.")
time.sleep(1)
print("You find yourself in a creepy dining hall.")
time.sleep(1)
print("There's a table set for a meal with a covered dish.")
time.sleep(1)
print("Open the dish or leave?")
choice = input("Enter 'open' or 'leave': ")
if choice.lower() == 'open':
print("\nYou lift the cover and find a key!")
time.sleep(1)
print("The key might be useful.")
time.sleep(1)
enter_house()
elif choice.lower() == 'leave':
print("\nYou decide to leave the dining hall.")
time.sleep(1)
enter_house()
else:
print("Invalid choice. Please enter 'open' or 'leave'.")
door_middle()
def door_right():
print("\nYou chose the door on the right.")
time.sleep(1)
print("You enter a spooky bedroom.")
time.sleep(1)
print("There's a large wardrobe against the wall.")
time.sleep(1)
print("Search the wardrobe or leave?")
choice = input("Enter 'search' or 'leave': ")
if choice.lower() == 'search':
print("\nYou search the wardrobe and find a creepy doll.")
time.sleep(1)
print("The doll's eyes seem to follow you.")
time.sleep(1)
enter_house()
elif choice.lower() == 'leave':
print("\nYou decide to leave the bedroom.")
time.sleep(1)
enter_house()
else:
print("Invalid choice. Please enter 'search' or 'leave'.")
door_right()
def explore_secret_room():
print("\nYou enter the secret room.")
time.sleep(1)
print("It's filled with cobwebs and old chests.")
time.sleep(1)
print("You open a chest and find the hidden treasure!")
time.sleep(1)
print("Congratulations! You win!")
play_again()
def play_again():
print("\nDo you want to play again?")
choice = input("Enter 'yes' or 'no': ")
if choice.lower() == 'yes':
game_start()
elif choice.lower() == 'no':
print("Thank you for playing!")
else:
print("Invalid choice. Please enter 'yes' or 'no'.")
play_again()
if __name__ == "__main__":
game_start()