Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
|
4 |
+
# Initialize or reset game state
|
5 |
+
def initialize_state():
|
6 |
+
st.session_state.update({
|
7 |
+
'current_act': 1,
|
8 |
+
'character': None,
|
9 |
+
'knowledge': 0,
|
10 |
+
'has_solved_puzzles': False,
|
11 |
+
'defeated_threat': False
|
12 |
+
})
|
13 |
+
|
14 |
+
if 'initialized' not in st.session_state:
|
15 |
+
initialize_state()
|
16 |
+
st.session_state.initialized = True
|
17 |
+
|
18 |
+
# Characters with more detailed attributes
|
19 |
+
characters = {
|
20 |
+
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful, with a deep connection to magical forces."},
|
21 |
+
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning and resourceful, skilled in potions and spells."}
|
22 |
+
}
|
23 |
+
|
24 |
+
# Enhanced story acts with more detailed descriptions
|
25 |
+
acts = [
|
26 |
+
{"name": "Introduction", "description": "Embark on your journey to find the Great Tree."},
|
27 |
+
{"name": "The Quest", "description": "Navigate the enchanted forest to discover the tree and its hidden workshop."},
|
28 |
+
{"name": "The Light and Shadow", "description": "Learn the secrets of the workshop and master magical crafts."},
|
29 |
+
{"name": "The Final Battle", "description": "Confront the looming threat to save the tree's magic."},
|
30 |
+
{"name": "Conclusion", "description": "Celebrate your victory and reflect on the journey."}
|
31 |
+
]
|
32 |
+
|
33 |
+
# Main Streamlit application
|
34 |
+
def main():
|
35 |
+
st.title("The Magic Workshop In The Great Tree π³β¨")
|
36 |
+
|
37 |
+
# Character selection and description
|
38 |
+
if st.session_state.character is None:
|
39 |
+
st.header("Choose your character π§ββοΈπ§ββοΈ")
|
40 |
+
character = st.selectbox("Select your character", options=list(characters.keys()), format_func=lambda x: f"{x} {characters[x]['emoji']}")
|
41 |
+
st.write(characters[character]["description"])
|
42 |
+
if st.button("Choose"):
|
43 |
+
st.session_state.character = character
|
44 |
+
st.session_state.knowledge += characters[character]["knowledge"]
|
45 |
+
st.experimental_rerun()
|
46 |
+
|
47 |
+
# Display current act and description
|
48 |
+
act = acts[st.session_state.current_act - 1]
|
49 |
+
st.header(f"Act {st.session_state.current_act}: {act['name']}")
|
50 |
+
st.subheader(act["description"])
|
51 |
+
|
52 |
+
# Act-specific interactions
|
53 |
+
if st.session_state.current_act == 1:
|
54 |
+
quest_for_tree()
|
55 |
+
elif st.session_state.current_act == 2:
|
56 |
+
enter_workshop()
|
57 |
+
elif st.session_state.current_act == 3:
|
58 |
+
final_battle()
|
59 |
+
elif st.session_state.current_act == 4:
|
60 |
+
conclusion()
|
61 |
+
|
62 |
+
# Restart option
|
63 |
+
if st.session_state.current_act > 1 and st.button("Restart the adventure"):
|
64 |
+
initialize_state()
|
65 |
+
st.experimental_rerun()
|
66 |
+
|
67 |
+
def quest_for_tree():
|
68 |
+
if st.button("Search for the Great Tree π"):
|
69 |
+
if roll_dice() > 3:
|
70 |
+
st.success("You've found the Great Tree! π³")
|
71 |
+
st.session_state.current_act += 1
|
72 |
+
else:
|
73 |
+
st.error("You wander but find nothing. Try again!")
|
74 |
+
|
75 |
+
def enter_workshop():
|
76 |
+
if not st.session_state.has_solved_puzzles:
|
77 |
+
if st.button("Solve puzzles to enter the workshop π§©"):
|
78 |
+
if roll_dice() + st.session_state.knowledge > 7:
|
79 |
+
st.success("You solved the puzzles and entered the workshop! πβ¨")
|
80 |
+
st.session_state.has_solved_puzzles = True
|
81 |
+
else:
|
82 |
+
st.error("The puzzles baffle you. Perhaps there's something you're missing?")
|
83 |
+
else:
|
84 |
+
st.write("You're inside the workshop, learning its secrets. πβοΈ")
|
85 |
+
if st.button("Learn the final secret"):
|
86 |
+
st.session_state.knowledge += 5
|
87 |
+
st.session_state.current_act += 1
|
88 |
+
|
89 |
+
def final_battle():
|
90 |
+
if not st.session_state.defeated_threat:
|
91 |
+
if st.button("Confront the threat π‘οΈπ‘οΈ"):
|
92 |
+
if roll_dice(2) + st.session_state.knowledge > 10:
|
93 |
+
st.success("You've defeated the threat and saved the tree's magic! π³β¨")
|
94 |
+
st.session_state.defeated_threat = True
|
95 |
+
st.session_state.current_act += 1
|
96 |
+
else:
|
97 |
+
st.error("You are not yet strong enough. Seek more knowledge and try again.")
|
98 |
+
else:
|
99 |
+
st.session_state.current_act += 1
|
100 |
+
|
101 |
+
def conclusion():
|
102 |
+
st.header("Congratulations! ππ")
|
103 |
+
st.write("You've completed 'The Magic Workshop In The Great Tree'.")
|
104 |
+
st.write("Through your journey, you've learned the value of knowledge, bravery, and sacrifice.")
|
105 |
+
|
106 |
+
# Helper function for dice rolls
|
107 |
+
def roll_dice(number_of_dice=1, sides=6):
|
108 |
+
return sum([random.randint(1, sides) for _ in range(number_of_dice)])
|
109 |
+
|
110 |
+
if __name__ == "__main__":
|
111 |
+
main()
|