awacke1's picture
Create app.py
1b8a61e verified
raw
history blame
4.58 kB
import streamlit as st
import random
# Initialize or reset game state
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 with more detailed attributes
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."}
}
# Enhanced story acts with more detailed descriptions
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."}
]
# Main Streamlit application
def main():
st.title("The Magic Workshop In The Great Tree 🌳✨")
# Character selection and description
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()
# Display current act and description
act = acts[st.session_state.current_act - 1]
st.header(f"Act {st.session_state.current_act}: {act['name']}")
st.subheader(act["description"])
# Act-specific interactions
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()
# Restart option
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.")
# Helper function for dice rolls
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()