awacke1's picture
Update app.py
863e252
raw
history blame
2.96 kB
import streamlit as st
import pandas as pd
import random
import base64
st.markdown("""
๐ŸŽฒ: This is the standard die used in many games, with each face showing a different number from 1 to 6.
๐ŸŽฏ: 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.
๐ŸŽด: 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.
๐ŸŽฐ: 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.
๐ŸŽณ: 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.
๐ŸŽฎ: 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.
๐ŸŽด: 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.
๐Ÿ€„: 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.
""")
# set up the game board
player_pos = {'Player 1': [0, 0], 'Player 2': [0, 0]}
board = pd.DataFrame(index=range(5), columns=range(5))
board.iloc[player_pos['Player 1'][0], player_pos['Player 1'][1]] = '๐ŸŽด'
board.iloc[player_pos['Player 2'][0], player_pos['Player 2'][1]] = '๐ŸŽด'
# implement the dice game
rolls = []
coins = {'Player 1': 0, 'Player 2': 0}
def roll_dice(player):
roll = random.randint(1, 6)
rolls.append(roll)
if roll in rolls[:-1]:
coins[player] += 10
# save results to file
results = pd.DataFrame(columns=['Player', 'Roll'])
def save_results(player, roll):
results.loc[len(results)] = [player, roll]
results.to_csv('results.txt', index=False)
# implement download link
def get_table_download_link(df, text):
csv = df.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode()
href = f'<a href="data:file/csv;base64,{b64}" download="{text}.csv">Download Results</a>'
return href
# create multiplayer aspect
players = ['Player 1', 'Player 2']
player = st.selectbox('Select Player', players)
player_pos[player][1] = st.slider('Move Right or Left', -2, 2, 0)
player_pos[player][0] = st.slider('Move Up or Down', -2, 2, 0)
board.iloc[player_pos['Player 1'][0], player_pos['Player 1'][1]] = '๐ŸŽฎ'
board.iloc[player_pos['Player 2'][0], player_pos['Player 2'][1]] = '๐ŸŽฒ'
if st.button('Roll Dice'):
roll_dice(player)
st.write('Roll:', rolls[-1])
st.write('Coins:', coins[player])
save_results(player, rolls[-1])
st.write(board)
if st.button('Download Results'):
st.markdown(get_table_download_link(results, 'results'), unsafe_allow_html=True)