Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
import datetime
|
4 |
+
import pytz
|
5 |
+
|
6 |
+
# Define the emojis and class names
|
7 |
+
classes = {
|
8 |
+
u'Engineering': {'emojis': [u'๐ ๏ธ', u'๐ง', u'๐ฉ', u'๐จ', u'๐']},
|
9 |
+
u'Magic': {'emojis': [u'๐ง', u'๐ฎ', u'โจ', u'๐', u'๐ฉ']},
|
10 |
+
u'Industry': {'emojis': [u'๐ญ', u'๐', u'๐จ', u'๐๏ธ', u'๐']}
|
11 |
+
}
|
12 |
+
|
13 |
+
# Define the function to roll the dice
|
14 |
+
def roll_dice(emojis):
|
15 |
+
return [random.choice(emojis) for i in range(20)]
|
16 |
+
|
17 |
+
# Define the function to check for three of a kind
|
18 |
+
def check_three_of_a_kind(dice):
|
19 |
+
for emoji in set(dice):
|
20 |
+
if dice.count(emoji) >= 3:
|
21 |
+
return True
|
22 |
+
return False
|
23 |
+
|
24 |
+
# Define the function to save the results to a file
|
25 |
+
def save_results(class_name, result):
|
26 |
+
now = datetime.datetime.now(pytz.timezone('US/Pacific'))
|
27 |
+
date_str = now.strftime('%Y-%m-%d')
|
28 |
+
time_str = now.strftime('%I-%M-%S-%p')
|
29 |
+
if now.hour >= 6 and now.hour < 18:
|
30 |
+
day_night_emoji = u'โ๏ธ'
|
31 |
+
else:
|
32 |
+
day_night_emoji = u'๐'
|
33 |
+
filename = f'{class_name}-{date_str}-{time_str}-{day_night_emoji}.txt'
|
34 |
+
with open(filename, 'wb') as f:
|
35 |
+
f.write(f'{class_name}: {result}'.encode('utf-8'))
|
36 |
+
|
37 |
+
# Define the Streamlit app
|
38 |
+
def main():
|
39 |
+
st.title("Roll the Dice Game")
|
40 |
+
st.write("Select a class to roll for:")
|
41 |
+
class_selection = st.selectbox("", list(classes.keys()))
|
42 |
+
|
43 |
+
emojis = classes[class_selection]['emojis']
|
44 |
+
class_name = class_selection.lower()
|
45 |
+
|
46 |
+
st.write(f"Selected class: {class_selection}")
|
47 |
+
st.write("Click the button to roll the dice:")
|
48 |
+
|
49 |
+
rolls_left = 3
|
50 |
+
dice_rolled = False
|
51 |
+
while rolls_left > 0 and not dice_rolled:
|
52 |
+
if st.button("Roll the Dice"):
|
53 |
+
dice = roll_dice(emojis)
|
54 |
+
dice_words = [emoji.encode('unicode_escape').decode('utf-8') for emoji in dice]
|
55 |
+
st.write("Dice:", " ".join(dice_words))
|
56 |
+
if check_three_of_a_kind(dice):
|
57 |
+
st.write("Congratulations! You rolled three of a kind!")
|
58 |
+
dice_rolled = True
|
59 |
+
result = 'win'
|
60 |
+
else:
|
61 |
+
st.write("You did not roll three of a kind. Try again.")
|
62 |
+
result = 'loss'
|
63 |
+
rolls_left -= 1
|
64 |
+
|
65 |
+
if not dice_rolled:
|
66 |
+
st.write("Sorry, you did not roll three of a kind. Better luck next time.")
|
67 |
+
result = 'loss'
|
68 |
+
|
69 |
+
save_results(class_name, result)
|
70 |
+
|
71 |
+
if __name__ == "__main__":
|
72 |
+
main()
|