File size: 3,841 Bytes
1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 1b8a61e e3400e8 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 |
import streamlit as st
import random
# Function to initialize or reset the game state
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, locations, and sightings with more RPG-like elements
characters = {
"Wizard": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Wise and powerful, connected to magical forces."},
"Witch": {"emoji": "π§ββοΈ", "knowledge": 5, "description": "Cunning, skilled in potions and spells."}
}
# Random sightings for each area to add to the story's atmosphere
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"],
# Add similar lists for other locations
}
# Main Streamlit application
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) # Display 3 random sightings
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') # Roll a d20 for major choices
handle_choice(choice, outcome)
def handle_choice(choice, outcome):
# Example: Adjust logic based on dice roll outcome
if 'effect' in choice:
if outcome > 10: # Adjust thresholds as needed for game balance
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):
# Example: Implement effect handling logic, like finding items or getting lost
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}!")
# More effects can be added here
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()
|