Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
|
4 |
+
# Define the initial session state if not already set
|
5 |
+
if 'current_step' not in st.session_state:
|
6 |
+
st.session_state['current_step'] = 1
|
7 |
+
if 'dice_roll' not in st.session_state:
|
8 |
+
st.session_state['dice_roll'] = 0
|
9 |
+
|
10 |
+
# Function to roll a dice and update the state
|
11 |
+
def roll_dice():
|
12 |
+
st.session_state.dice_roll = random.randint(1, 6)
|
13 |
+
|
14 |
+
# Function to advance the story based on dice roll and choices
|
15 |
+
def advance_story():
|
16 |
+
if st.session_state.dice_roll in [1, 2]:
|
17 |
+
st.session_state.current_step += 1
|
18 |
+
elif st.session_state.dice_roll in [3, 4, 5]:
|
19 |
+
st.session_state.current_step += 2
|
20 |
+
else:
|
21 |
+
st.session_state.current_step += 3
|
22 |
+
|
23 |
+
# Define your story steps and dramatic situations
|
24 |
+
story_steps = {
|
25 |
+
1: "Introduction to the World and Characters ππ₯",
|
26 |
+
2: "Discovery of the Problem (Pandemic) π¦ π·",
|
27 |
+
3: "The Quest Begins (Gathering Allies, Information) πΊοΈπ¬",
|
28 |
+
4: "First Major Challenge (Obtaining the First Ingredient) πΏπ₯",
|
29 |
+
5: "Confrontation with the Antagonist βοΈπ‘οΈ",
|
30 |
+
6: "Final Challenge and Discovery of the Cure ππ",
|
31 |
+
7: "Resolution and New Beginnings π
π±",
|
32 |
+
}
|
33 |
+
|
34 |
+
# App title
|
35 |
+
st.title("Discovery of a Safe Haven")
|
36 |
+
|
37 |
+
# Display current step in the story
|
38 |
+
current_step_text = story_steps.get(st.session_state.current_step, "The end. Restart the app to play again.")
|
39 |
+
st.markdown(f"## Step {st.session_state.current_step}: {current_step_text}")
|
40 |
+
|
41 |
+
# User interactions
|
42 |
+
st.button("Roll Dice", on_click=roll_dice)
|
43 |
+
st.write(f"Dice rolled: {st.session_state.dice_roll} π²")
|
44 |
+
|
45 |
+
# Advance story button only appears if dice is rolled
|
46 |
+
if st.session_state.dice_roll > 0:
|
47 |
+
st.button("Advance Story", on_click=advance_story)
|
48 |
+
|
49 |
+
# Display an expander with game rules
|
50 |
+
with st.expander("Game Rules"):
|
51 |
+
st.table([
|
52 |
+
{"Step": 1, "Description": "Introduction to the World and Characters", "Emoji": "ππ₯"},
|
53 |
+
{"Step": 2, "Description": "Discovery of the Problem (Pandemic)", "Emoji": "π¦ π·"},
|
54 |
+
{"Step": 3, "Description": "The Quest Begins (Gathering Allies, Information)", "Emoji": "πΊοΈπ¬"},
|
55 |
+
{"Step": 4, "Description": "First Major Challenge (Obtaining the First Ingredient)", "Emoji": "πΏπ₯"},
|
56 |
+
{"Step": 5, "Description": "Confrontation with the Antagonist", "Emoji": "βοΈπ‘οΈ"},
|
57 |
+
{"Step": 6, "Description": "Final Challenge and Discovery of the Cure", "Emoji": "ππ"},
|
58 |
+
{"Step": 7, "Description": "Resolution and New Beginnings", "Emoji": "π
π±"},
|
59 |
+
])
|
60 |
+
|
61 |
+
# Optionally, add file uploader for custom content (e.g., user-created story elements)
|
62 |
+
st.file_uploader("Upload your story elements")
|
63 |
+
|
64 |
+
# Optionally, add camera input for user to add their picture as a character
|
65 |
+
st.camera_input("Take a picture to add your character")
|
66 |
+
|
67 |
+
# Remember to check for necessary packages and install them before running the app
|
68 |
+
# pip install streamlit
|