import streamlit as st import pandas as pd import plotly.express as px import random from streamlit_flow import streamlit_flow from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge from streamlit_flow.layouts import RadialLayout def generate_situation(): situations = [ "The Village in Peril", "The Cursed Artifact", "The Sacred Pact", "The Shapeshifter's Challenge", "The Fox Fire Trial" ] return random.choice(situations) def generate_action(): actions = [ "Use Fox Fire", "Shapeshift", "Possess an Object", "Call Upon Ancient Spirits", "Use Mystical Artifact" ] return random.choice(actions) def evaluate_action(situation, action, power_level, mystical_energy): success_chance = (power_level + mystical_energy) / 2 outcome = random.randint(1, 100) <= success_chance return outcome, success_chance def update_graph(nodes, edges, situation, action, outcome): new_node_id = f"{situation}-{action}" new_node = StreamlitFlowNode(new_node_id, (0, 0), {'content': f"{situation}\n{action}\nOutcome: {'Success' if outcome else 'Failure'}"}, 'output', 'bottom', 'top') nodes.append(new_node) if len(nodes) > 1: new_edge = StreamlitFlowEdge(f"{nodes[-2].id}-{new_node.id}", nodes[-2].id, new_node.id, animated=True) edges.append(new_edge) return nodes, edges def app(): st.markdown("# Kitsune - The Mystical Shape-Shifter Game 🦊") if 'nodes' not in st.session_state: st.session_state.nodes = [] st.session_state.edges = [] st.session_state.score = 0 # Game Stats st.sidebar.markdown("## Game Stats") st.sidebar.markdown(f"Score: {st.session_state.score}") # Character Stats power_level = st.sidebar.slider('Power Level ⚡', 0, 100, 50) mystical_energy = st.sidebar.slider('Mystical Energy ✨', 0, 100, 75) # Game Loop if st.button('Next Turn'): situation = generate_situation() action = generate_action() outcome, success_chance = evaluate_action(situation, action, power_level, mystical_energy) st.markdown(f"## Current Situation: {situation}") st.markdown(f"You decided to: {action}") st.markdown(f"Outcome: {'Success!' if outcome else 'Failure.'}") st.markdown(f"Success Chance: {success_chance:.2f}%") if outcome: st.session_state.score += 1 st.session_state.nodes, st.session_state.edges = update_graph(st.session_state.nodes, st.session_state.edges, situation, action, outcome) # Display Graph if st.session_state.nodes: streamlit_flow('kitsune_game_flow', st.session_state.nodes, st.session_state.edges, layout=RadialLayout(), fit_view=True, height=600) # Character Stats Visualization data = {"Stat": ["Power Level", "Mystical Energy"], "Value": [power_level, mystical_energy]} df = pd.DataFrame(data) fig = px.bar(df, x='Stat', y='Value', title="Kitsune Stats 📊") st.plotly_chart(fig) if __name__ == "__main__": app()