File size: 4,728 Bytes
c11db43
49a4692
c11db43
 
5e13f0c
c11db43
5e13f0c
 
c11db43
 
5e13f0c
 
 
 
 
 
 
 
 
 
 
c11db43
5e13f0c
 
 
 
 
 
 
c11db43
5e13f0c
c11db43
4c86fb8
5e13f0c
 
c11db43
5e13f0c
c11db43
5e13f0c
 
 
 
 
c11db43
5e13f0c
 
 
 
c11db43
 
5e13f0c
c11db43
5e13f0c
 
 
 
 
c11db43
 
5e13f0c
 
 
 
 
 
 
 
c11db43
5e13f0c
 
 
 
 
 
 
 
 
39bd597
88bab31
 
 
 
 
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
import os
import pandas as pd
import streamlit as st

# Set page title and icon
st.set_page_config(page_title="Dice Roller", page_icon="๐ŸŽฒ")

# Set page title
st.title("๐ŸŽฒ Dice Roller")

# Check if username is already set, if not, create a text input to set it
if 'username' not in st.session_state:
    st.session_state.username = st.text_input("๐Ÿ‘ค Username", max_chars=50)

# Define the dice types
dice_types = {
    "๐ŸŽฒ Six-sided dice": {"sides": 6, "name": "d6", "emoji": "๐ŸŽฒ"},
    "๐ŸŽฒ Thirty-sided dice": {"sides": 30, "name": "d30", "emoji": "๐ŸŽฒ"},
    "๐ŸŽฒ Twenty-sided dice": {"sides": 20, "name": "d20", "emoji": "๐ŸŽฒ"},
    "๐ŸŽฒ One hundred-sided dice": {"sides": 100, "name": "d100", "emoji": "๐Ÿ’ฏ"},
}

# Create a function to build the rolls pandas series to be a list of dictionaries
def build_rolls(dice_type, num_rolls):
    sides = dice_types[dice_type]["sides"]
    rolls = pd.Series([sides] * num_rolls).apply(pd.Series.sample, replace=True)
    rolls = rolls.tolist()
    count = sum(rolls)
    return [{"Roll": roll, "Count": count, "DiceNumberOfSides": sides} for roll in rolls]

# Create a selectbox to choose the dice type
dice_type = st.selectbox("๐ŸŽฒ Select a dice type", options=list(dice_types.keys()), format_func=lambda x: x.split(' ')[-2])

# Create a slider to choose the number of rolls
num_rolls = st.slider("๐ŸŽฒ How many times do you want to roll the dice?", 1, 1000000, 100)

# Create a button to roll the dice
if st.button("๐ŸŽฒ Roll Dice"):
    # Build the rolls list of dictionaries
    rolls = build_rolls(dice_type, num_rolls)

    # Display the rolls
    display_roll = [roll["Roll"] for roll in rolls]
    st.write(f"{dice_types[dice_type]['emoji']} You rolled {len(display_roll)} {dice_types[dice_type]['name']} dice: {', '.join(map(str, display_roll))}.")

    # Check if the count is a multiple of the dice sides to see if there's a bonus match
    bonus_match = None
    count = rolls[0]["Count"]
    if count % dice_types[dice_type]['sides'] == 0:
        bonus_match = dice_types[dice_type]['name']
        bonus_emoji = dice_types[dice_type]['emoji']
        st.write(f"๐ŸŽ‰ Bonus match! You rolled a multiple of {dice_types[dice_type]['sides']}.")

    # Create a DataFrame with the rolls, count, and dice number of sides
    df = pd.DataFrame(rolls)

    # Check if the file exists
    file_exists = os.path.exists("SharedState.csv")

    # Append the new rolls to the file
    if file_exists:
        df.to_csv("SharedState.csv", mode='a', header=False, index=False)
    # If the file doesn't exist, create it and write the headers
    else:
        df.to_csv("SharedState.csv", mode='w', header=True, index=False)

# Create a checkbox to download the roll history
download_roll_history = st.checkbox("๐Ÿ“ฅ Download Roll History", value=True)

# Check if the file exists and display it as a download link
if os.path.exists("SharedState.csv") and download_roll_history:
    with open("SharedState.csv", "r") as f:
        file_contents = f.read()
    st.markdown(f"<a href='data:file/csv;base64,{file_contents.encode().b64encode()}'>๐Ÿ“ฅ Download Roll History</a>", unsafe_allow_html=True)




st.write("""

๐Ÿž Bread, ๐Ÿฅ Croissant, ๐Ÿฅ– Baguette Bread, ๐Ÿซ“ Flatbread, ๐Ÿฅจ Pretzel, ๐Ÿฅฏ Bagel, ๐Ÿฅž Pancakes, ๐Ÿง‡ Waffle, ๐Ÿง€ Cheese Wedge, ๐Ÿ– Meat on Bone, ๐Ÿ— Poultry Leg, ๐Ÿฅฉ Cut of Meat, ๐Ÿฅ“ Bacon, ๐Ÿ” Hamburger, ๐ŸŸ French Fries, ๐Ÿ• Pizza, ๐ŸŒญ Hot Dog, ๐Ÿฅช Sandwich, ๐ŸŒฎ Taco, ๐ŸŒฏ Burrito, ๐Ÿซ” Tamale, ๐Ÿฅ™ Stuffed Flatbread, ๐Ÿง† Falafel, ๐Ÿฅš Egg, ๐Ÿณ Cooking, ๐Ÿฅ˜ Shallow Pan of Food, ๐Ÿฒ Pot of Food, ๐Ÿซ• Fondue, ๐Ÿฅฃ Bowl with Spoon, ๐Ÿฅ— Green Salad, ๐Ÿฟ Popcorn, ๐Ÿงˆ Butter, ๐Ÿง‚ Salt, ๐Ÿฅซ Canned Food, ๐Ÿฑ Bento Box, ๐Ÿ˜ Rice Cracker, ๐Ÿ™ Rice Ball, ๐Ÿš Cooked Rice, ๐Ÿ› Curry Rice, ๐Ÿœ Steaming Bowl, ๐Ÿ Spaghetti, ๐Ÿ  Roasted Sweet Potato, ๐Ÿข Oden, ๐Ÿฃ Sushi, ๐Ÿค Fried Shrimp, ๐Ÿฅ Fish Cake with Swirl, ๐Ÿฅฎ Moon Cake, ๐Ÿก Dango, ๐ŸฅŸ Dumpling, ๐Ÿฅ  Fortune Cookie, ๐Ÿฅก Takeout Box, ๐Ÿฆช Oyster, ๐Ÿฆ Soft Ice Cream, ๐Ÿง Shaved Ice, ๐Ÿจ Ice Cream, ๐Ÿฉ Doughnut, ๐Ÿช Cookie, ๐ŸŽ‚ Birthday Cake, ๐Ÿฐ Shortcake, ๐Ÿง Cupcake, ๐Ÿฅง Pie, ๐Ÿซ Chocolate Bar, ๐Ÿฌ Candy, ๐Ÿญ Lollipop, ๐Ÿฎ Custard, ๐Ÿฏ Honey Pot, ๐Ÿผ Baby Bottle, ๐Ÿฅ› Glass of Milk, โ˜• Hot Beverage, ๐Ÿซ– Teapot, ๐Ÿต Teacup Without Handle, ๐Ÿถ Sake, ๐Ÿพ Bottle with Popping Cork, ๐Ÿท Wine Glass, ๐Ÿธ Cocktail Glass, ๐Ÿน Tropical Drink, ๐Ÿบ Beer Mug, ๐Ÿป Clinking Beer Mugs, ๐Ÿฅ‚ Clinking Glasses, ๐Ÿฅƒ Tumbler Glass, ๐Ÿซ— Pouring Liquid, ๐Ÿฅค Cup with Straw, ๐Ÿง‹ Bubble Tea, ๐Ÿงƒ Beverage Box, ๐Ÿง‰ Mate, ๐ŸงŠ Ice, ๐Ÿฅข Chopsticks, ๐Ÿฝ๏ธ Fork and Knife with Plate, ๐Ÿด Fork and Knife, ๐Ÿฅ„ Spoon, ๐Ÿซ™ Jar")
""")