Keeby-smilyai commited on
Commit
5b53945
Β·
verified Β·
1 Parent(s): 0441065

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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")