Spaces:
Runtime error
Runtime error
import streamlit as st | |
import random | |
import datetime | |
import pytz | |
# Define the emojis and class names | |
classes = { | |
'Engineering': {'emojis': ['๐ ๏ธ', '๐ง', '๐ฉ', '๐จ', '๐']}, | |
'Magic': {'emojis': ['๐ง', '๐ฎ', 'โจ', '๐', '๐ฉ']}, | |
'Industry': {'emojis': ['๐ญ', '๐', '๐จ', '๐๏ธ', '๐']} | |
} | |
# Define the function to roll the dice | |
def roll_dice(emojis): | |
return [random.choice(emojis) for i in range(20)] | |
# Define the function to check for three of a kind | |
def check_three_of_a_kind(dice): | |
for emoji in set(dice): | |
if dice.count(emoji) >= 3: | |
return True | |
return False | |
# Define the function to save the results to a file | |
def save_results(class_name, result): | |
now = datetime.datetime.now(pytz.timezone('US/Pacific')) | |
date_str = now.strftime('%Y-%m-%d') | |
time_str = now.strftime('%I-%M-%S-%p') | |
if now.hour >= 6 and now.hour < 18: | |
day_night_emoji = 'โ๏ธ' | |
else: | |
day_night_emoji = '๐' | |
filename = f'{class_name}-{date_str}-{time_str}-{day_night_emoji}.txt' | |
with open(filename, 'w') as f: | |
f.write(f'{class_name}: {result}') | |
# Define the Streamlit app | |
def main(): | |
st.title("Roll the Dice Game") | |
st.write("Select a class to roll for:") | |
class_selection = st.selectbox("", list(classes.keys())) | |
emojis = classes[class_selection]['emojis'] | |
class_name = class_selection.lower() | |
st.write(f"Selected class: {class_selection}") | |
st.write("Click the button to roll the dice:") | |
rolls_left = 3 | |
dice_rolled = False | |
while rolls_left > 0 and not dice_rolled: | |
if st.button("Roll the Dice"): | |
dice = roll_dice(emojis) | |
dice_words = [emoji.encode('unicode_escape').decode('utf-8') for emoji in dice] | |
st.write("Dice:", " ".join(dice_words)) | |
if check_three_of_a_kind(dice): | |
st.write("Congratulations! You rolled three of a kind!") | |
dice_rolled = True | |
result = 'win' | |
else: | |
st.write("You did not roll three of a kind. Try again.") | |
result = 'loss' | |
rolls_left -= 1 | |
if not dice_rolled: | |
st.write("Sorry, you did not roll three of a kind. Better luck next time.") | |
result = 'loss' | |
save_results(class_name, result) | |
if __name__ == "__main__": | |
main() | |