File size: 3,290 Bytes
423482b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()