File size: 2,988 Bytes
9974cac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import random
import time
from datetime import datetime

# Constants
EMOJIS = ["🎯", "πŸš€", "🌟", "🌈", "πŸ”₯"]
OBJECTS_MONSTERS = ["Sword", "Shield", "Potion", "Dragon", "Goblin", "Elf", "Orc"]
CHAT_HISTORY_LENGTH = 5
ACTION_HISTORY_LENGTH = 5

# Ensure data files exist
def ensure_data_files():
    files = ['players.txt', 'chat.txt', 'actions.txt', 'objects.txt']
    for f in files:
        try:
            with open(f, 'r') as file:
                pass
        except FileNotFoundError:
            with open(f, 'w') as file:
                file.write('')

# Add player
def add_player(name):
    with open('players.txt', 'a') as file:
        file.write(name + '\n')

# Get all players
def get_all_players():
    with open('players.txt', 'r') as file:
        return [line.strip() for line in file.readlines()]

# Add chat message
def add_chat_message(name, message):
    with open('chat.txt', 'a') as file:
        file.write(name + ': ' + message + '\n')

# Get recent chat messages
def get_recent_chat_messages():
    with open('chat.txt', 'r') as file:
        return file.readlines()[-CHAT_HISTORY_LENGTH:]

# Add action
def add_action(name, action):
    with open('actions.txt', 'a') as file:
        file.write(name + ': ' + action + '\n')

# Get recent actions
def get_recent_actions():
    with open('actions.txt', 'r') as file:
        return file.readlines()[-ACTION_HISTORY_LENGTH:]

# Streamlit interface
def app():
    st.title("Emoji Battle Game!")

    # Ensure data files exist
    ensure_data_files()

    # Player name input
    player_name = st.text_input("Enter your name:")
    if player_name and player_name not in get_all_players():
        add_player(player_name)

    players = get_all_players()
    st.write(f"Players: {', '.join(players)}")

    # Display timer and emoji buttons
    st.write("Click on the emoji when the timer reaches 0!")
    timer = st.empty()
    for i in range(3, 0, -1):
        timer.write(f"Timer: {i}")
        time.sleep(1)
    timer.write("Timer: 0")

    emoji_clicked = st.button(random.choice(EMOJIS))
    if emoji_clicked and player_name:
        add_action(player_name, "Clicked the emoji!")

    # Display recent actions
    st.write("Recent Actions:")
    for action in get_recent_actions():
        st.write(action.strip())

    # Interactions with objects and monsters
    interaction = st.selectbox("Choose an interaction:", OBJECTS_MONSTERS)
    if st.button("Interact") and player_name:
        add_action(player_name, f"Interacted with {interaction}")

    # Chat
    chat_message = st.text_input("Send a message:")
    if st.button("Send") and player_name:
        add_chat_message(player_name, chat_message)

    st.write("Recent chat messages:")
    for message in get_recent_chat_messages():
        st.write(message.strip())

    # Refresh every 3 seconds
    st.write("Refreshing in 3 seconds...")
    time.sleep(3)
    st.experimental_rerun()

# Run the Streamlit app
app()