|
import streamlit as st |
|
import random |
|
|
|
|
|
def initialize_state(): |
|
st.session_state.update({ |
|
'current_act': 1, |
|
'character': None, |
|
'knowledge': 0, |
|
'has_solved_puzzles': False, |
|
'defeated_threat': False |
|
}) |
|
|
|
if 'initialized' not in st.session_state: |
|
initialize_state() |
|
st.session_state.initialized = True |
|
|
|
|
|
characters = { |
|
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful, with a deep connection to magical forces."}, |
|
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning and resourceful, skilled in potions and spells."} |
|
} |
|
|
|
|
|
acts = [ |
|
{"name": "Introduction", "description": "Embark on your journey to find the Great Tree."}, |
|
{"name": "The Quest", "description": "Navigate the enchanted forest to discover the tree and its hidden workshop."}, |
|
{"name": "The Light and Shadow", "description": "Learn the secrets of the workshop and master magical crafts."}, |
|
{"name": "The Final Battle", "description": "Confront the looming threat to save the tree's magic."}, |
|
{"name": "Conclusion", "description": "Celebrate your victory and reflect on the journey."} |
|
] |
|
|
|
|
|
def main(): |
|
st.title("The Magic Workshop In The Great Tree π³β¨") |
|
|
|
|
|
if st.session_state.character is None: |
|
st.header("Choose your character π§ββοΈπ§ββοΈ") |
|
character = st.selectbox("Select your character", options=list(characters.keys()), format_func=lambda x: f"{x} {characters[x]['emoji']}") |
|
st.write(characters[character]["description"]) |
|
if st.button("Choose"): |
|
st.session_state.character = character |
|
st.session_state.knowledge += characters[character]["knowledge"] |
|
st.experimental_rerun() |
|
|
|
|
|
act = acts[st.session_state.current_act - 1] |
|
st.header(f"Act {st.session_state.current_act}: {act['name']}") |
|
st.subheader(act["description"]) |
|
|
|
|
|
if st.session_state.current_act == 1: |
|
quest_for_tree() |
|
elif st.session_state.current_act == 2: |
|
enter_workshop() |
|
elif st.session_state.current_act == 3: |
|
final_battle() |
|
elif st.session_state.current_act == 4: |
|
conclusion() |
|
|
|
|
|
if st.session_state.current_act > 1 and st.button("Restart the adventure"): |
|
initialize_state() |
|
st.experimental_rerun() |
|
|
|
def quest_for_tree(): |
|
if st.button("Search for the Great Tree π"): |
|
if roll_dice() > 3: |
|
st.success("You've found the Great Tree! π³") |
|
st.session_state.current_act += 1 |
|
else: |
|
st.error("You wander but find nothing. Try again!") |
|
|
|
def enter_workshop(): |
|
if not st.session_state.has_solved_puzzles: |
|
if st.button("Solve puzzles to enter the workshop π§©"): |
|
if roll_dice() + st.session_state.knowledge > 7: |
|
st.success("You solved the puzzles and entered the workshop! πβ¨") |
|
st.session_state.has_solved_puzzles = True |
|
else: |
|
st.error("The puzzles baffle you. Perhaps there's something you're missing?") |
|
else: |
|
st.write("You're inside the workshop, learning its secrets. πβοΈ") |
|
if st.button("Learn the final secret"): |
|
st.session_state.knowledge += 5 |
|
st.session_state.current_act += 1 |
|
|
|
def final_battle(): |
|
if not st.session_state.defeated_threat: |
|
if st.button("Confront the threat π‘οΈπ‘οΈ"): |
|
if roll_dice(2) + st.session_state.knowledge > 10: |
|
st.success("You've defeated the threat and saved the tree's magic! π³β¨") |
|
st.session_state.defeated_threat = True |
|
st.session_state.current_act += 1 |
|
else: |
|
st.error("You are not yet strong enough. Seek more knowledge and try again.") |
|
else: |
|
st.session_state.current_act += 1 |
|
|
|
def conclusion(): |
|
st.header("Congratulations! ππ") |
|
st.write("You've completed 'The Magic Workshop In The Great Tree'.") |
|
st.write("Through your journey, you've learned the value of knowledge, bravery, and sacrifice.") |
|
|
|
|
|
def roll_dice(number_of_dice=1, sides=6): |
|
return sum([random.randint(1, sides) for _ in range(number_of_dice)]) |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|