awacke1's picture
Create app.py
90c2d38 verified
raw
history blame contribute delete
No virus
2.92 kB
import streamlit as st
import random
# Define the initial session state if not already set
if 'current_step' not in st.session_state:
st.session_state['current_step'] = 1
if 'dice_roll' not in st.session_state:
st.session_state['dice_roll'] = 0
# Function to roll a dice and update the state
def roll_dice():
st.session_state.dice_roll = random.randint(1, 6)
# Function to advance the story based on dice roll and choices
def advance_story():
if st.session_state.dice_roll in [1, 2]:
st.session_state.current_step += 1
elif st.session_state.dice_roll in [3, 4, 5]:
st.session_state.current_step += 2
else:
st.session_state.current_step += 3
# Define your story steps and dramatic situations
story_steps = {
1: "Introduction to the World and Characters 🌎πŸ‘₯",
2: "Discovery of the Problem (Pandemic) 🦠😷",
3: "The Quest Begins (Gathering Allies, Information) πŸ—ΊοΈπŸ‘¬",
4: "First Major Challenge (Obtaining the First Ingredient) 🌿πŸ”₯",
5: "Confrontation with the Antagonist βš”οΈπŸ›‘οΈ",
6: "Final Challenge and Discovery of the Cure πŸ’‰πŸŽ‰",
7: "Resolution and New Beginnings πŸŒ…πŸŒ±",
}
# App title
st.title("Discovery of a Safe Haven")
# Display current step in the story
current_step_text = story_steps.get(st.session_state.current_step, "The end. Restart the app to play again.")
st.markdown(f"## Step {st.session_state.current_step}: {current_step_text}")
# User interactions
st.button("Roll Dice", on_click=roll_dice)
st.write(f"Dice rolled: {st.session_state.dice_roll} 🎲")
# Advance story button only appears if dice is rolled
if st.session_state.dice_roll > 0:
st.button("Advance Story", on_click=advance_story)
# Display an expander with game rules
with st.expander("Game Rules"):
st.table([
{"Step": 1, "Description": "Introduction to the World and Characters", "Emoji": "🌎πŸ‘₯"},
{"Step": 2, "Description": "Discovery of the Problem (Pandemic)", "Emoji": "🦠😷"},
{"Step": 3, "Description": "The Quest Begins (Gathering Allies, Information)", "Emoji": "πŸ—ΊοΈπŸ‘¬"},
{"Step": 4, "Description": "First Major Challenge (Obtaining the First Ingredient)", "Emoji": "🌿πŸ”₯"},
{"Step": 5, "Description": "Confrontation with the Antagonist", "Emoji": "βš”οΈπŸ›‘οΈ"},
{"Step": 6, "Description": "Final Challenge and Discovery of the Cure", "Emoji": "πŸ’‰πŸŽ‰"},
{"Step": 7, "Description": "Resolution and New Beginnings", "Emoji": "πŸŒ…πŸŒ±"},
])
# Optionally, add file uploader for custom content (e.g., user-created story elements)
st.file_uploader("Upload your story elements")
# Optionally, add camera input for user to add their picture as a character
st.camera_input("Take a picture to add your character")
# Remember to check for necessary packages and install them before running the app
# pip install streamlit