Spaces:
Sleeping
Sleeping
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 |