|
import streamlit as st |
|
import random |
|
|
|
|
|
def initialize_state(): |
|
st.session_state.update({ |
|
'current_act': 1, |
|
'location': 'forest edge', |
|
'character': None, |
|
'knowledge': 0, |
|
'inventory': [], |
|
'has_solved_puzzles': False, |
|
'defeated_threat': False, |
|
'sightings': [] |
|
}) |
|
|
|
if 'initialized' not in st.session_state: |
|
initialize_state() |
|
st.session_state.initialized = True |
|
|
|
|
|
characters = { |
|
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful, connected to magical forces."}, |
|
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning, skilled in potions and spells."} |
|
} |
|
|
|
|
|
area_sightings = { |
|
'forest edge': ["a fluttering butterfly", "a distant owl hoot", "rustling leaves", "a mysterious fog", "glimmering fireflies", "a fallen, ancient tree", "a curious squirrel", "a shadowy figure in the distance", "a sparkling brook", "footprints leading off the path"], |
|
'deep forest': ["a deer darting away", "a whispering breeze", "a hidden pond", "a canopy of interlocking branches", "a sudden chill", "the call of a raven", "a circle of mushrooms", "an abandoned nest", "a ray of sunlight breaking through", "a moss-covered rock"], |
|
|
|
} |
|
|
|
|
|
def main(): |
|
st.title("The Magic Workshop In The Great Tree π³β¨") |
|
|
|
if st.session_state.character is None: |
|
choose_character() |
|
else: |
|
display_sightings() |
|
navigate_story() |
|
|
|
def choose_character(): |
|
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() |
|
|
|
def display_sightings(): |
|
current_location = st.session_state.location |
|
if current_location in area_sightings: |
|
sightings = random.sample(area_sightings[current_location], 3) |
|
st.write(f"As you explore, you notice: {', '.join(sightings)}.") |
|
|
|
def navigate_story(): |
|
location = locations[st.session_state.location] |
|
st.subheader(location['description']) |
|
for choice in location['choices']: |
|
if st.button(choice['text']): |
|
outcome = roll_dice('d20') |
|
handle_choice(choice, outcome) |
|
|
|
def handle_choice(choice, outcome): |
|
|
|
if 'effect' in choice: |
|
if outcome > 10: |
|
apply_effect(choice['effect']) |
|
else: |
|
st.write("Your attempt was not successful this time.") |
|
if 'next' in choice: |
|
st.session_state.location = choice['next'] |
|
st.experimental_rerun() |
|
|
|
def apply_effect(effect): |
|
|
|
if effect == "find item": |
|
item = random.choice(["mysterious key", "ancient coin", "magic potion"]) |
|
st.session_state.inventory.append(item) |
|
st.write(f"You found a {item}!") |
|
|
|
|
|
def roll_dice(dice_type): |
|
if dice_type == 'd20': |
|
return random.randint(1, 20) |
|
elif dice_type == 'd10': |
|
return random.randint(1, 10) |
|
elif dice_type == 'd6': |
|
return random.randint(1, 6) |
|
else: |
|
return 0 |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|