Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
#Import the necessary libraries
|
3 |
+
import streamlit as st
|
4 |
+
import random
|
5 |
+
|
6 |
+
#Set up the game
|
7 |
+
st.title("Welcome to Zork!")
|
8 |
+
st.write("You are in a dark, damp cave. You can see a faint light in the distance and hear a distant rumbling sound.")
|
9 |
+
|
10 |
+
#Create a list of available moves
|
11 |
+
moves = ["Go left", "Go right", "Go forward", "Go backward"]
|
12 |
+
|
13 |
+
#Create a loop to allow the user to make moves
|
14 |
+
while True:
|
15 |
+
st.write("What do you want to do?")
|
16 |
+
move = st.selectbox("Choose your move:", moves)
|
17 |
+
|
18 |
+
if move == "Go left":
|
19 |
+
st.write("You go left and find yourself in a small room. There is a lever in the corner.")
|
20 |
+
lever = st.selectbox("Do you pull the lever?", ["Yes", "No"])
|
21 |
+
if lever == "Yes":
|
22 |
+
st.write("You pull the lever and a door opens. You walk through the door and find yourself in a large chamber with a treasure chest!")
|
23 |
+
break
|
24 |
+
else:
|
25 |
+
st.write("You decide not to pull the lever and continue exploring the cave.")
|
26 |
+
elif move == "Go right":
|
27 |
+
st.write("You go right and find yourself in a large room. There is a giant monster blocking your path!")
|
28 |
+
monster = st.selectbox("Do you try to fight the monster?", ["Yes", "No"])
|
29 |
+
if monster == "Yes":
|
30 |
+
monster_hp = random.randint(1,10)
|
31 |
+
player_hp = random.randint(1,10)
|
32 |
+
st.write("You attack the monster with all your might! You hit it for {} damage, but it hits you back for {} damage!".format(player_hp, monster_hp))
|
33 |
+
if player_hp > monster_hp:
|
34 |
+
st.write("You defeated the monster! You continue exploring the cave and eventually find your way out.")
|
35 |
+
break
|
36 |
+
else:
|
37 |
+
st.write("The monster was too strong! You are defeated.")
|
38 |
+
break
|
39 |
+
else:
|
40 |
+
st.write("You decide not to fight the monster and continue exploring the cave.")
|
41 |
+
elif move == "Go forward":
|
42 |
+
st.write("You go forward and find yourself in a large chamber. There is a treasure chest in the center of the room!")
|
43 |
+
treasure = st.selectbox("Do you open the treasure chest?", ["Yes", "No"])
|
44 |
+
if treasure == "Yes":
|
45 |
+
st.write("You open the chest and find a mysterious artifact inside. You take the artifact and continue exploring the cave.")
|
46 |
+
break
|
47 |
+
else:
|
48 |
+
st.write("You decide not to open the chest and continue exploring the cave.")
|
49 |
+
elif move == "Go backward":
|
50 |
+
st.write("You go backward and find yourself in a dead end. There is nothing else to do here.")
|