File size: 3,033 Bytes
3faf85b
880ed84
dbd74a6
880ed84
 
 
 
 
 
 
cc48e9f
880ed84
 
 
 
 
 
dbd74a6
880ed84
 
 
3ca52be
880ed84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ca52be
880ed84
dbd74a6
 
880ed84
 
 
 
 
3faf85b
880ed84
 
 
 
 
 
 
 
 
 
 
 
 
3ca52be
880ed84
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
import gradio as gr
import random

# Стан NPC
npc_states = {
    "початковий": "NPC переживає перші кроки самопізнання.",
    "в пошуку": "NPC намагається знайти свій шлях у світі.",
    "світлий": "NPC став провідником для інших, пізнав світло.",
    "бог": "NPC досяг стану бога і управляє космічним порядком."
}

# Статуси гри
game_status = {
    "active": "Гра триває. NPC розвивається.",
    "victory": "Ви виграли! NPC досяг стану бога.",
    "defeat": "Ви програли... Сумніви зупинили прогрес."
}

# Глобальні змінні
current_game_status = "active"
current_npc_state = "початковий"

# Функція оновлення NPC
def update_npc_state():
    global current_npc_state
    states = list(npc_states.keys())
    current_index = states.index(current_npc_state)
    if current_index < len(states) - 1:
        current_npc_state = states[current_index + 1]
    else:
        global current_game_status
        current_game_status = "victory"

# Основна функція для взаємодії
def interact_with_npc(choice):
    global current_game_status
    if current_game_status != "active":
        return game_status[current_game_status], npc_states[current_npc_state]
    
    if choice == "1":  # Вперед
        update_npc_state()
        message = "NPC зробив крок вперед!"
    elif choice == "2":  # Сумніви
        current_game_status = "defeat"
        message = "NPC зупинився через ваші сумніви."
    else:
        message = "Некоректний вибір. NPC очікує вашого рішення."
    
    return game_status[current_game_status], npc_states[current_npc_state]

# Інтерфейс Gradio
def reset_game():
    global current_game_status, current_npc_state
    current_game_status = "active"
    current_npc_state = "початковий"
    return "active", npc_states["початковий"]

with gr.Blocks() as demo:
    gr.Markdown("## NPC Familia: Духовний розвиток вашого персонажа")
    current_status = gr.Textbox(label="Статус гри", value="active", interactive=False)
    current_state = gr.Textbox(label="Стан NPC", value=npc_states["початковий"], interactive=False)
    
    with gr.Row():
        btn_forward = gr.Button("Крок вперед")
        btn_doubt = gr.Button("Сумніви")
        btn_reset = gr.Button("Почати заново")
    
    btn_forward.click(fn=lambda: interact_with_npc("1"), inputs=[], outputs=[current_status, current_state])
    btn_doubt.click(fn=lambda: interact_with_npc("2"), inputs=[], outputs=[current_status, current_state])
    btn_reset.click(fn=reset_game, inputs=[], outputs=[current_status, current_state])

demo.launch()