File size: 4,269 Bytes
24795a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c82718a
24795a1
 
 
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
import streamlit as st
import random
import time
from datetime import datetime

# Constants
EMOJIS = ["🎯", "🚀", "🐔", "🌮", "🍩", "🤖", "🎩"]
OBJECTS_MONSTERS = ["Spork", "Magic Sock", "Laughing Potion", "Ticklish Dragon", "Dancing Goblin", "Elf with Bad Jokes", "Orc who thinks he's a Chef"]
CHAT_HISTORY_LENGTH = 5
ACTION_HISTORY_LENGTH = 5
SCORE_HISTORY_LENGTH = 5

# Ensure data files exist
def ensure_data_files():
    files = ['players.txt', 'chat.txt', 'actions.txt', 'objects.txt', 'scores.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:]

# Add score
def add_score(name, score):
    with open('scores.txt', 'a') as file:
        file.write(name + ': ' + str(score) + '\n')

# Get recent scores
def get_recent_scores(name):
    with open('scores.txt', 'r') as file:
        return [line for line in file.readlines() if name in line][-SCORE_HISTORY_LENGTH:]

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

    # 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 for a surprise!")
    timer = st.empty()
    for i in range(3, 0, -1):
        timer.write(f"Timer: {i}")
        time.sleep(1)
    timer.write("Timer: 0")

    chosen_emoji = random.choice(EMOJIS)
    emoji_clicked = st.button(chosen_emoji)
    if emoji_clicked and player_name:
        event = random.choice(["won a dance battle", "ate too many tacos", "got tickled by a ghost", "found a magic spork"])
        action_message = f"{player_name} {event} with {chosen_emoji}"
        add_action(player_name, action_message)

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

    # Interactions with objects and monsters
    interaction = st.selectbox("Choose a funny interaction:", OBJECTS_MONSTERS)
    if st.button("Interact") and player_name:
        dice_roll = random.randint(1, 6)
        outcome = f"rolled a {dice_roll} and"
        if dice_roll > 4:
            outcome += f" successfully made friends with {interaction}!"
            score = 10
        else:
            outcome += f" had a laugh-off with {interaction}!"
            score = 5
        action_message = f"{player_name} {outcome}"
        add_action(player_name, action_message)
        add_score(player_name, score)

    # Chat
    chat_message = st.text_input("Send a funny 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())

    # Display recent scores
    if player_name:
        st.write(f"{player_name}'s Recent Scores:")
        for score in get_recent_scores(player_name):
            st.write(score.strip())

    # Refresh every 5 seconds for better user experience
    st.write("Refreshing in 5 seconds...")
    time.sleep(5)
    st.rerun()

# Run the Streamlit app
app()