Skip to content

Commit 62229ef

Browse files
authored
Merge pull request #183 from bcsamrudh/main
Haunted House[GUI]
2 parents 0087bcc + 192edb7 commit 62229ef

File tree

5 files changed

+138
-80
lines changed

5 files changed

+138
-80
lines changed

Haunted House/Image/img.png

-152 KB
Binary file not shown.

Haunted House/Readme.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
**Haunted House**
1+
**Haunted House[GUI]**
22

33
**GOAL**
44

55
The aim of this program is to is to escape the house with the loot. Using NESTED DICTIONARY data type.
66

77
**DESCRIPTION**
88

9-
Use the ccommand to navigate in the house and explore the adventure.
9+
Use the command to navigate in the house and explore the adventure.
1010

1111
Commands:
1212
- use [item] eg: use key
@@ -20,14 +20,20 @@ Commands:
2020
**LIBRARIES NEEDED**
2121

2222
- time
23+
- tkinter
24+
- tkinter.ttk
25+
- sys
2326

2427
**HOW TO RUN**
2528
- from the terminal line run cmd <pre><code>python3 haunted_house.py</code></pre>
2629

2730
**DEMONSTRATION**
2831

29-
<img width="722" alt="img" src="https://user-images.githubusercontent.com/83280091/210749512-953e8a97-a8d8-48a5-8933-3203215cc3dc.png">
32+
![demo_image](https://user-images.githubusercontent.com/114090255/216824210-1f6f8889-47bd-43b5-9847-0d6ed9ccf385.png)
3033

3134
**YOUR NAME**
3235

36+
3337
Govind Kushwaha
38+
39+
B C Samrudh

Haunted House/demo_image.png

63.5 KB
Loading

Haunted House/haunted_house.py

+125-76
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
1-
# Haunted House with python
1+
from tkinter import *
2+
import sys
3+
from tkinter.ttk import *
24
import time
35

4-
def welcome():
5-
print(" /\\")
6-
print(" / \\")
7-
print(" /\ / \\ ")
8-
print(" / \ / \ ")
9-
print(" / \/ \_/\\")
10-
print(" / Welcome to \\")
11-
print(" / \\")
12-
print(" | the Haunted House! |")
13-
print(" | ____ ___ |")
14-
print(" | | | |___| |")
15-
print("__|____|____|___________|__")
16-
print("")
17-
time.sleep(1)
18-
19-
welcome()
20-
21-
def showInstructions():
22-
print('''
23-
Commands:
24-
use [item] eg: use key
25-
26-
shoot[enemy] eg: shoot zombie
27-
28-
go [direction] eg: go north
29-
30-
get [object] eg: get bandage
31-
''')
32-
33-
health= 100
34-
35-
def showStatus():
6+
health=100
367

37-
print('You are in the ' + currentRoom)
38-
print (rooms[currentRoom]['desc'])
39-
print("Inventory : " + str(inventory))
40-
print("Your health is",health)
41-
if "item" in rooms[currentRoom]:
42-
print('You see a ' + rooms[currentRoom]['item'])
43-
print("---------------------------")
44-
45-
46-
478
inventory = []
489

4910
monster=[]
@@ -80,80 +41,168 @@ def showStatus():
8041

8142
currentRoom = 'Hall'
8243

83-
showInstructions()
8444

85-
while True:
45+
def welcome():
46+
label = Label(window, text="Welcome to the Haunted House!")
47+
label.pack()
48+
49+
def show_instructions():
50+
instructions=Message(new_window,text='''
51+
Commands:
52+
use [item] eg: use key
53+
54+
shoot[enemy] eg: shoot zombie
55+
56+
go [direction] eg: go north
57+
58+
get [object] eg: get bandage
59+
''')
60+
instructions.pack()
8661

87-
showStatus()
62+
def showStatus():
63+
health_bar['value']=health
64+
window.update_idletasks()
65+
health_bar.pack()
66+
location_label=Label(window,text='You are in the ' + currentRoom)
67+
location_label.pack()
68+
desc_label=Label(window,text=rooms[currentRoom]['desc'])
69+
desc_label.pack()
70+
inventory_label=Label(window,text=f"Inventory : {str(inventory)}")
71+
inventory_label.pack()
72+
if "item" in rooms[currentRoom]:
73+
message_label=Label(window,text=f"You see a {rooms[currentRoom]['item']}")
74+
message_label.pack()
8875

89-
move = ''
90-
while move == '':
91-
move = input('>')
76+
def game(move):
77+
global currentRoom
78+
global inventory
79+
global health
9280

93-
move = move.lower().split()
94-
95-
if move[0]=="shoot":
81+
if move[0]=="shoot":
9682
if "monster"in rooms[currentRoom] and move[1] in rooms[currentRoom]['monster'] and "shotgun" in inventory :
9783
del rooms[currentRoom]['monster']
98-
print( "you killed the", move[1])
84+
message_label=Label(window,text=f"you killed the {move[1]}")
85+
message_label.pack()
9986
rooms[currentRoom].update({"monster":"dead"},)
10087

10188
else:
102-
print("you cannot attack " )
103-
89+
message_label=Label(window,text="you cannot attack " )
90+
message_label.pack()
10491

105-
106-
if move[0]=="use":
92+
if move[0]=="exit":
93+
time.sleep(1)
94+
sys.exit()
95+
96+
if move[0]=="use":
10797

10898

10999
if "bandage" in inventory and move[1]== "bandage":
110100
heal=40
111101
health=min(100,health+heal)
112102
inventory.remove("bandage")
113-
print("you recovered 40 health (max 100)")
103+
message_label=Label(window,text="you recovered 40 health (max 100)")
104+
message_label.pack()
114105

115106
elif "key" in inventory and move[1]== "key" and "golden_crown" in inventory and currentRoom=="Garden":
116-
print("you escape with the loot, you retire in style, you win!! ")
117-
break
107+
message_label=Label(window,text="you escape with the loot, you retire in style, you win!! ")
108+
message_label.pack()
109+
#here the program doesn't display the message it exits after 1 second
110+
time.sleep(1)
111+
sys.exit()
118112

119113

120114
elif "key" in inventory and move[1]== "key" in inventory and currentRoom=="Garden":
121-
print("you escape the house but die a pauper, you lose ")
122-
break
115+
message_label=Label(window,text="you escape the house but die a pauper, you lose ")
116+
message_label.pack()
117+
#here the program doesn't display the message it exits after 1 second
118+
time.sleep(1)
119+
sys.exit()
123120

124121

125122

126123
else:
127-
print("can't use that")
124+
message_label=Label(window,text="can't use that")
125+
message_label.pack()
128126

129127

130128

131-
if move[0] == 'go':
129+
if move[0] == 'go':
132130
if move[1] in rooms[currentRoom]:
133131
currentRoom = rooms[currentRoom][move[1]]
134132
else:
135-
print('You can\'t go that way!')
133+
message_label=Label(window,text=r"You can\'t go that way!")
134+
message_label.pack()
136135

137-
if move[0] == 'get' :
136+
if move[0] == 'get' :
138137

139138
if 'item' in rooms[currentRoom] and move[1] in rooms[currentRoom]['item']:
140139
inventory += [move[1]]
141-
print(move[1] + ' got!')
140+
message_label=Label(window,text=f"{move[1]} got!")
141+
message_label.pack()
142142
del rooms[currentRoom]['item']
143143

144144
else:
145-
print("Can\'t get that")
145+
message_label=Label(window,text=r"Can\'t get that")
146+
message_label.pack()
146147

147-
if 'zombie' in rooms[currentRoom]['monster']:
148-
print("A zombie attack you !!!")
148+
if 'zombie' in rooms[currentRoom]['monster']:
149+
message_label=Label(window,text="A zombie attack you !!!")
150+
message_label.pack()
149151
health=health-30
150152

151-
if 'ghoul' in rooms[currentRoom]['monster']:
152-
print('A ghoul attack you !!!')
153+
if 'ghoul' in rooms[currentRoom]['monster']:
154+
message_label=Label(window,text='A ghoul attack you !!!')
155+
message_label.pack()
153156
health=health-20
157+
158+
if health<0:
159+
message_label=Label(window,text="you are dead")
160+
message_label.pack()
154161

162+
def get_input():
163+
showStatus()
164+
input=Entry(window,width=25)
165+
input.pack()
166+
submit_Button=Button(window,text="Submit", command=lambda:submit(input))
167+
submit_Button.pack()
168+
169+
def submit(input):
170+
move = input.get().lower().split()
171+
if input.get():
172+
game(move)
173+
else:
174+
Error_Lab=Label(window,text="Please Enter something")
175+
Error_Lab.pack()
176+
get_input()
177+
178+
window=Tk()
179+
window.title("Haunted House Game")
180+
window.geometry('500x500')
181+
182+
new_window=Toplevel(window)
183+
new_window.title("Commands")
184+
185+
#tried to create a scrollbar but it did not work
186+
187+
#frame-Frame(window)
188+
# frame.pack(,fill=BOTH)
189+
190+
# canvas = Canvas(frame,yscrollcommand=scrollbar.set)
191+
# canvas.pack(fill=BOTH, expand=True)
192+
193+
# scrollbar.config(command=canvas.yview)
194+
195+
196+
health_bar= Progressbar(window, orient = HORIZONTAL, length = 100, mode = 'determinate')
197+
198+
welcome()
199+
200+
show_instructions()
201+
202+
health_meter=Label(window,text="Your Health")
203+
204+
health_meter.pack()
205+
206+
get_input()
155207

156-
if health <= 0:
157-
print("you are dead")
158-
break
159-
208+
window.mainloop()

Haunted House/requirements.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## LIBRARIES NEEDED
22

33
import time
4+
import tkinter
5+
import tkinter.ttk
6+
import sys
47

58
Commands:
69
- use [item] eg: use key
@@ -9,4 +12,4 @@ Commands:
912

1013
- go [direction] eg: go north
1114

12-
- get [object] eg: get bandage
15+
- get [object] eg: get bandage

0 commit comments

Comments
 (0)