Spaces:
Sleeping
Sleeping
File size: 12,507 Bytes
0fbec67 6f86ef3 0fbec67 6f86ef3 0fbec67 6f86ef3 0fbec67 6f86ef3 0fbec67 6f86ef3 0fbec67 6f86ef3 0fbec67 6f86ef3 0fbec67 d4ea9dc 6f86ef3 0fbec67 60b006e 0fbec67 6f86ef3 0fbec67 60b006e 0fbec67 6f86ef3 d4ea9dc 0fbec67 6f86ef3 0fbec67 60b006e 6f86ef3 60b006e 6f86ef3 60b006e |
1 2 3 4 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
import streamlit as st
import pandas as pd
import plotly.express as px
import random
import uuid
from datetime import datetime
from streamlit_flow import streamlit_flow
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
from streamlit_flow.layouts import TreeLayout
# ๐ Game World Data - SITUATIONS and ACTIONS expanded with humorous elements
SITUATIONS = [
{
"id": "feline_escape",
"name": "The Great Feline Escape",
"description": "Your cat rider is trapped in an old mansion, which is about to be demolished. Using agility, wit, and bravery, orchestrate the perfect escape before the walls crumble! ๐๏ธ",
"emoji": "๐ช",
"type": "escape"
},
{
"id": "lost_temple",
"name": "The Treasure of the Lost Temple",
"description": "On a quest to retrieve an ancient artifact, your cat rider must navigate through a labyrinth filled with traps and guardian spirits. Don't let the spooky ghosts get you! ๐ป",
"emoji": "๐๏ธ",
"type": "exploration"
},
{
"id": "royal_tournament",
"name": "The Royal Tournament",
"description": "Compete in a grand tournament where the finest cat riders showcase their skills and bravery to earn the title of the Royal Rider. Be prepared to face noble feline adversaries! ๐ฑ",
"emoji": "๐",
"type": "competition"
},
{
"id": "cheese_heist",
"name": "The Great Cheese Heist",
"description": "Your cat rider must sneak into the royal pantry to steal the legendary Cheese of Destiny. But beware โ the palace mice are guarding it! ๐ง",
"emoji": "๐ง",
"type": "heist"
},
{
"id": "sky_race",
"name": "The Sky Race",
"description": "Compete in the annual Sky Race where your cat rider flies across the skies on a magical broomstick! Watch out for lightning storms and mischievous crows! ๐ฉ๏ธ",
"emoji": "โ๏ธ",
"type": "competition"
},
{
"id": "purr_summit",
"name": "The Purr Summit",
"description": "Join a secret gathering of the most intellectual cats in the world. Engage in a battle of wits and wisdom to become the Grand Purr! ๐ง ",
"emoji": "๐",
"type": "debate"
},
{
"id": "cat_nap",
"name": "The Eternal Catnap",
"description": "You've entered a sacred temple where cats nap for centuries. Can you navigate the dream world and escape before you too are lulled into eternal slumber? ๐๏ธ",
"emoji": "๐ค",
"type": "exploration"
},
{
"id": "feline_moon_mission",
"name": "The Feline Moon Mission",
"description": "Blast off into space! Your mission is to plant the flag of Catopia on the moon. But first, you must pilot your rocket through an asteroid field. ๐",
"emoji": "๐",
"type": "exploration"
},
{
"id": "pirate_cove",
"name": "The Pirate Cove",
"description": "Sail the high seas with your trusty crew of cats and uncover the secrets of the Pirate Cove. But beware of the treacherous Sea Dogs! ๐ดโโ ๏ธ",
"emoji": "๐ดโโ ๏ธ",
"type": "exploration"
},
{
"id": "cat_casino",
"name": "The Cat Casino",
"description": "Test your luck in the glamorous Cat Casino! Bet your whiskers on the tables and try not to lose it all. Meow is the time! ๐ฒ",
"emoji": "๐ฐ",
"type": "competition"
}
]
ACTIONS = [
{
"id": "stealth",
"name": "Use Stealth",
"description": "Sneak past obstacles or enemies without being detected. You're like a ninja in the shadows! ๐พ",
"emoji": "๐คซ",
"type": "skill"
},
{
"id": "agility",
"name": "Showcase Agility",
"description": "Perform impressive acrobatic maneuvers to overcome challenges. Cats always land on their feet, right? ๐",
"emoji": "๐",
"type": "physical"
},
{
"id": "charm",
"name": "Charm Others",
"description": "Use your cat's natural charisma to win over allies or distract foes. Who could resist those cute eyes? ๐ป",
"emoji": "๐ป",
"type": "social"
},
{
"id": "resourcefulness",
"name": "Be Resourceful",
"description": "Utilize the environment or items in creative ways to solve problems. Think on your paws! ๐ง ",
"emoji": "๐ง ",
"type": "mental"
},
{
"id": "bravery",
"name": "Show Bravery",
"description": "Face dangers head-on with your feline courage. Not all heroes wear capes โ some wear fur! ๐ฆธโโ๏ธ",
"emoji": "๐ฆธโโ๏ธ",
"type": "physical"
},
{
"id": "negotiation",
"name": "Negotiate",
"description": "Use diplomacy and clever negotiation to get out of a tight spot. Every cat has their price! ๐ผ",
"emoji": "๐ผ",
"type": "social"
},
{
"id": "precision",
"name": "Precision Attack",
"description": "Execute a perfectly timed attack to disable traps or defeat enemies. Purrfection in motion! ๐ฏ",
"emoji": "๐ฏ",
"type": "skill"
},
{
"id": "distraction",
"name": "Create a Distraction",
"description": "Use cunning tricks and diversions to draw attention away from your real goal. Look over there! ๐ช",
"emoji": "๐ช",
"type": "mental"
},
{
"id": "speed",
"name": "Sprint Away",
"description": "Run faster than you've ever run before to escape danger. Just like a cat fleeing a vacuum cleaner! ๐โโ๏ธ",
"emoji": "๐โโ๏ธ",
"type": "physical"
},
{
"id": "insight",
"name": "Use Insight",
"description": "Tap into ancient feline wisdom to solve puzzles and mysteries. A cat always knows! ๐ฎ",
"emoji": "๐ฎ",
"type": "mental"
}
]
# Expanded conclusions for outcomes - 10 items each for success and failure
SUCCESS_CONCLUSIONS = [
"Your swift paws led you to victory! ๐",
"You pounced at the perfect moment! ๐",
"The stars aligned for your cat rider! ๐",
"You navigated the challenge like a true feline champion! ๐ฑ",
"Victory is sweet, just like a bowl of fresh milk! ๐ฅ",
"Your opponents are left in awe of your skills! ๐บ",
"Youโve earned the title of Cat Commander! ๐
",
"All the other cats are jealous of your agility! ๐โโ๏ธ",
"Your strategy was flawless, and the victory is yours! ๐๏ธ",
"Your cat rider is now a legend in the feline world! ๐"
]
FAILURE_CONCLUSIONS = [
"You tried your best, but it just wasnโt enough. ๐ฟ",
"Maybe next time, kitty. Keep your tail up! ๐พ",
"That didnโt go as planned. Time for a catnap to recover! ๐ค",
"Even the best cats have their off days. ๐",
"The challenge was too great this time. Better luck next time! ๐",
"You might need more than nine lives to get through this. ๐",
"The enemy was too clever for your plan. ๐ง ",
"You tripped over your own paws! ๐พ",
"The cat gods were not in your favor today. ๐",
"Itโs okay, every cat has a learning curve. ๐"
]
# Function to generate encounter conclusions
def generate_encounter_conclusion(situation, action, outcome):
if outcome:
return random.choice(SUCCESS_CONCLUSIONS)
else:
return random.choice(FAILURE_CONCLUSIONS)
# Function to generate a random situation
def generate_situation():
return random.choice(SITUATIONS)
# Function to generate random actions
def generate_actions():
return random.sample(ACTIONS, min(3, len(ACTIONS)))
# The rest of the code remains mostly the same
# ๐ฎ Main Game Application
def main():
st.title("๐ฑ Cat Rider ๐")
st.markdown("""
## Welcome to Cat Rider!
In this immersive adventure, you will explore the thrilling world of feline riders. This game sets the stage for dramatic situations and guided storytelling with engaging interactive elements.
""")
# ๐ Game Rules (unchanged)
st.markdown("""
### ๐ Game Rules
| ๐ค๏ธ Step | ๐ Description |
|---------|----------------|
| 1๏ธโฃ | Choose your Cat Rider |
| 2๏ธโฃ | Select the Riding Gear |
| 3๏ธโฃ | Set off on an Adventure |
| 4๏ธโฃ | Encounter Challenges and Make Decisions |
| 5๏ธโฃ | Complete the Quest and Grow Stronger |
""")
# ๐ Initialize game state
if 'game_state' not in st.session_state:
st.session_state.game_state = {
'user_id': str(uuid.uuid4()),
'score': 0,
'history': {},
'gear_strength': 5,
'rider_skill': 5,
'history_df': pd.DataFrame(columns=['user_id', 'timestamp', 'situation_id', 'situation_name', 'situation_emoji', 'situation_type', 'action_id', 'action_name', 'action_emoji', 'action_type', 'outcome', 'conclusion', 'gear_strength', 'rider_skill', 'score'])
}
# Main gameplay loop and event handling
situation = generate_situation()
actions = generate_actions()
# Display current situation and available actions
st.markdown(f"## {situation['emoji']} Current Situation: {situation['name']} ({situation['type']})")
st.markdown(situation['description'])
st.markdown("### ๐ญ Choose your action:")
cols = st.columns(3)
for i, action in enumerate(actions):
if cols[i].button(f"{action['emoji']} {action['name']} ({action['type']})"):
outcome, success_chance = evaluate_action(action, st.session_state.game_state['gear_strength'], st.session_state.game_state['rider_skill'], st.session_state.game_state['history'])
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
st.markdown(f"You decided to: **{action['name']}** ({action['type']})")
st.markdown(action['description'])
st.markdown(f"**Outcome:** {'โ
Success!' if outcome else 'โ Failure.'}")
st.markdown(f"**Success Chance:** {success_chance:.2f}%")
if outcome:
st.session_state.game_state['score'] += 1
# ๐ Update game state
st.session_state.game_state = update_game_state(
st.session_state.game_state,
situation,
action,
outcome,
timestamp
)
# Display conclusion
conclusion = st.session_state.game_state['history_df'].iloc[-1]['conclusion']
st.markdown(f"**Encounter Conclusion:** {conclusion}")
# Display updated stats
st.markdown(f"**Updated Stats:**")
st.markdown(f"๐ช Gear Strength: {st.session_state.game_state['gear_strength']:.2f}")
st.markdown(f"๐๏ธ Rider Skill: {st.session_state.game_state['rider_skill']:.2f}")
# ๐ Display Markdown Preview (unchanged)
if not st.session_state.game_state['history_df'].empty:
st.markdown(create_markdown_preview(st.session_state.game_state['history_df']))
# ๐ณ Display Heterogeneous Journey Graph (unchanged)
if not st.session_state.game_state['history_df'].empty:
st.markdown("## ๐ณ Your Journey (Heterogeneous Graph)")
nodes, edges = create_heterogeneous_graph(st.session_state.game_state['history_df'])
try:
streamlit_flow('cat_rider_flow',
nodes,
edges,
layout=TreeLayout(direction='down'),
fit_view=True,
height=600)
except Exception as e:
st.error(f"An error occurred while rendering the journey graph: {str(e)}")
st.markdown("Please try refreshing the page if the graph doesn't appear.")
# ๐ Character Stats Visualization
data = {"Stat": ["Gear Strength ๐ก๏ธ", "Rider Skill ๐"],
"Value": [st.session_state.game_state['gear_strength'], st.session_state.game_state['rider_skill']]}
df = pd.DataFrame(data)
fig = px.bar(df, x='Stat', y='Value', title="Cat Rider Stats ๐")
st.plotly_chart(fig)
if __name__ == "__main__":
main()
|