File size: 4,578 Bytes
1b8a61e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
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()
|