Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +112 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,114 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
| 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 |
-
st.
|
| 34 |
-
|
| 35 |
-
.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
|
| 4 |
+
st.set_page_config(page_title="Haunted Survival: Text Horror Game", layout="wide")
|
| 5 |
+
|
| 6 |
+
st.title("π Haunted Survival: Text Horror Game π")
|
| 7 |
+
st.markdown("You are the lone player among 99 teammates in a haunted, terrifying environment. Survive the night!")
|
| 8 |
+
|
| 9 |
+
# -----------------------------
|
| 10 |
+
# Help Section
|
| 11 |
+
# -----------------------------
|
| 12 |
+
st.sidebar.header("π Help & Support")
|
| 13 |
+
st.sidebar.markdown("""
|
| 14 |
+
If you are young or easily scared:
|
| 15 |
+
- Take breaks often
|
| 16 |
+
- Play in a well-lit room
|
| 17 |
+
- Remember it's just a game
|
| 18 |
+
|
| 19 |
+
**Therapist Chatbot:** Enter your message and get supportive responses.
|
| 20 |
+
""")
|
| 21 |
+
|
| 22 |
+
# Simple scripted therapist responses
|
| 23 |
+
therapist_responses = [
|
| 24 |
+
"It's okay to feel scared. Take a deep breath.",
|
| 25 |
+
"Remember, this is just a game. You're safe.",
|
| 26 |
+
"Feeling anxious is normal. Maybe step away for a moment?",
|
| 27 |
+
"Try focusing on something calm, like a favorite memory.",
|
| 28 |
+
"You are strong and can handle this. Even in a game."
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
user_message = st.sidebar.text_input("Talk to Therapist")
|
| 32 |
+
if st.sidebar.button("Send"):
|
| 33 |
+
if user_message.strip() != "":
|
| 34 |
+
st.sidebar.markdown(f"**Therapist:** {random.choice(therapist_responses)}")
|
| 35 |
+
else:
|
| 36 |
+
st.sidebar.markdown("**Therapist:** Say something when you're ready.")
|
| 37 |
+
|
| 38 |
+
# -----------------------------
|
| 39 |
+
# Game Setup
|
| 40 |
+
# -----------------------------
|
| 41 |
+
if "game_started" not in st.session_state:
|
| 42 |
+
st.session_state.game_started = False
|
| 43 |
+
st.session_state.turn = 0
|
| 44 |
+
st.session_state.ai_characters = []
|
| 45 |
+
|
| 46 |
+
# Start game
|
| 47 |
+
if not st.session_state.game_started:
|
| 48 |
+
player_name = st.text_input("Enter your name to start surviving:")
|
| 49 |
+
if st.button("Start Game") and player_name.strip() != "":
|
| 50 |
+
st.session_state.player_name = player_name.strip()
|
| 51 |
+
st.session_state.game_started = True
|
| 52 |
+
|
| 53 |
+
# Generate 99 AI teammates
|
| 54 |
+
first_names = ["Alex","Sam","Jordan","Taylor","Riley","Morgan","Casey","Jamie","Drew","Charlie"]
|
| 55 |
+
traits = ["coward","heroic","insane","silent","reckless","timid","brave","panicky","curious","suspicious"]
|
| 56 |
+
for i in range(1,100):
|
| 57 |
+
name = random.choice(first_names) + f"_{i}"
|
| 58 |
+
trait = random.choice(traits)
|
| 59 |
+
st.session_state.ai_characters.append({"name": name, "trait": trait, "status": "alive"})
|
| 60 |
+
st.experimental_rerun()
|
| 61 |
+
|
| 62 |
+
# -----------------------------
|
| 63 |
+
# Main Game Loop
|
| 64 |
+
# -----------------------------
|
| 65 |
+
if st.session_state.game_started:
|
| 66 |
+
st.markdown(f"**Player:** {st.session_state.player_name} (You always survive!)")
|
| 67 |
+
st.markdown(f"**Turn:** {st.session_state.turn + 1}")
|
| 68 |
+
|
| 69 |
+
# Possible events
|
| 70 |
+
locations = ["abandoned church", "foggy forest", "old mansion", "creepy alley", "dark basement"]
|
| 71 |
+
events_murder = [
|
| 72 |
+
"was found missing, only blood stains remain.",
|
| 73 |
+
"screamed and then vanished mysteriously.",
|
| 74 |
+
"fell from the staircase after seeing a shadow.",
|
| 75 |
+
"was dragged into darkness, no one saw how.",
|
| 76 |
+
]
|
| 77 |
+
events_supernatural = [
|
| 78 |
+
"a shadow flickered and whispered your name.",
|
| 79 |
+
"strange chanting echoed from the walls.",
|
| 80 |
+
"cold hands touched their shoulder, but no one was there.",
|
| 81 |
+
"an eerie fog swallowed them whole."
|
| 82 |
+
]
|
| 83 |
+
|
| 84 |
+
# Player chooses action
|
| 85 |
+
action = st.radio("Choose your action:", ["Explore the area", "Call out to teammates", "Hide and observe"])
|
| 86 |
+
|
| 87 |
+
st.markdown("### Turn Events:")
|
| 88 |
+
# AI actions
|
| 89 |
+
for ai in st.session_state.ai_characters:
|
| 90 |
+
if ai["status"] == "alive":
|
| 91 |
+
event_type = random.choice(["murder", "supernatural"])
|
| 92 |
+
location = random.choice(locations)
|
| 93 |
+
if event_type == "murder":
|
| 94 |
+
outcome = random.choice(events_murder)
|
| 95 |
+
else:
|
| 96 |
+
outcome = random.choice(events_supernatural)
|
| 97 |
+
st.markdown(f"- **{ai['name']}** ({ai['trait']}) in the {location} {outcome}")
|
| 98 |
+
|
| 99 |
+
# Randomly some AI "die" (not player!)
|
| 100 |
+
if random.random() < 0.15:
|
| 101 |
+
ai["status"] = "dead"
|
| 102 |
+
|
| 103 |
+
st.markdown(f"**Your action:** {action} (You survived this turn!)")
|
| 104 |
+
|
| 105 |
+
# Next turn
|
| 106 |
+
if st.button("Next Turn"):
|
| 107 |
+
st.session_state.turn += 1
|
| 108 |
+
st.experimental_rerun()
|
| 109 |
+
|
| 110 |
+
# Summary
|
| 111 |
+
alive_count = sum(1 for ai in st.session_state.ai_characters if ai["status"]=="alive")
|
| 112 |
+
dead_count = 99 - alive_count
|
| 113 |
+
st.markdown(f"**AI Teammates Alive:** {alive_count} / 99")
|
| 114 |
+
st.markdown(f"**AI Teammates Dead:** {dead_count} / 99")
|