Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
st.markdown("""
|
2 |
+
|
3 |
+
๐ฒ: This is the standard die used in many games, with each face showing a different number from 1 to 6.
|
4 |
+
|
5 |
+
๐ฏ: This emoji represents a dart board, but it can also be used to refer to a 6-sided die in which each face shows a different number from 1 to 6.
|
6 |
+
|
7 |
+
๐ด: This is a Japanese flower card game, but can also be used to represent a 6-sided die in which each face shows a different number from 1 to 6.
|
8 |
+
|
9 |
+
๐ฐ: This emoji represents a slot machine, but it can also be used to refer to a 6-sided die in which each face shows a different number from 1 to 6.
|
10 |
+
|
11 |
+
๐ณ: This emoji represents a bowling game, but it can also be used to refer to a 10-sided die in which each face shows a different number from 0 to 9.
|
12 |
+
|
13 |
+
๐ฎ: This emoji represents a video game controller, but it can also be used to refer to a 20-sided die often used in role-playing games, with each face showing a different number from 1 to 20.
|
14 |
+
|
15 |
+
๐ด: This is a Japanese flower card game, but it can also be used to represent a 6-sided die in which each face shows a different number from 1 to 6.
|
16 |
+
|
17 |
+
๐: This is a mahjong tile representing the one of circles, but it can also be used to represent a 6-sided die in which each face shows a different number from 1 to 6.
|
18 |
+
|
19 |
+
|
20 |
+
""")
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
import streamlit as st
|
25 |
+
import pandas as pd
|
26 |
+
import random
|
27 |
+
import base64
|
28 |
+
|
29 |
+
# set up the game board
|
30 |
+
player_pos = {'Player 1': [0, 0], 'Player 2': [0, 0]}
|
31 |
+
board = pd.DataFrame(index=range(5), columns=range(5))
|
32 |
+
board.iloc[player_pos['Player 1'][0], player_pos['Player 1'][1]] = 'P1'
|
33 |
+
board.iloc[player_pos['Player 2'][0], player_pos['Player 2'][1]] = 'P2'
|
34 |
+
|
35 |
+
# implement the dice game
|
36 |
+
rolls = []
|
37 |
+
coins = {'Player 1': 0, 'Player 2': 0}
|
38 |
+
def roll_dice(player):
|
39 |
+
roll = random.randint(1, 6)
|
40 |
+
rolls.append(roll)
|
41 |
+
if roll in rolls[:-1]:
|
42 |
+
coins[player] += 10
|
43 |
+
|
44 |
+
# save results to file
|
45 |
+
results = pd.DataFrame(columns=['Player', 'Roll'])
|
46 |
+
def save_results(player, roll):
|
47 |
+
results.loc[len(results)] = [player, roll]
|
48 |
+
results.to_csv('results.txt', index=False)
|
49 |
+
|
50 |
+
# implement download link
|
51 |
+
def get_table_download_link(df, text):
|
52 |
+
csv = df.to_csv(index=False)
|
53 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
54 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="{text}.csv">Download Results</a>'
|
55 |
+
return href
|
56 |
+
|
57 |
+
# create multiplayer aspect
|
58 |
+
players = ['Player 1', 'Player 2']
|
59 |
+
player = st.selectbox('Select Player', players)
|
60 |
+
player_pos[player][1] = st.slider('Move Right or Left', -2, 2, 0)
|
61 |
+
player_pos[player][0] = st.slider('Move Up or Down', -2, 2, 0)
|
62 |
+
board.iloc[player_pos['Player 1'][0], player_pos['Player 1'][1]] = 'P1'
|
63 |
+
board.iloc[player_pos['Player 2'][0], player_pos['Player 2'][1]] = 'P2'
|
64 |
+
|
65 |
+
if st.button('Roll Dice'):
|
66 |
+
roll_dice(player)
|
67 |
+
st.write('Roll:', rolls[-1])
|
68 |
+
st.write('Coins:', coins[player])
|
69 |
+
save_results(player, rolls[-1])
|
70 |
+
|
71 |
+
st.write(board)
|
72 |
+
|
73 |
+
if st.button('Download Results'):
|
74 |
+
st.markdown(get_table_download_link(results, 'results'), unsafe_allow_html=True)
|