File size: 3,153 Bytes
c11db43
ddb3454
4927d16
cc2268c
4927d16
1f9a1e6
cc2268c
 
 
 
 
 
 
 
 
 
 
1f9a1e6
cc2268c
 
1f9a1e6
cc2268c
0e81c8d
1f9a1e6
cc2268c
 
 
 
1f9a1e6
cc2268c
 
 
 
 
 
 
1f9a1e6
cc2268c
 
1f9a1e6
cc2268c
 
4927d16
1f9a1e6
cc2268c
 
4927d16
1f9a1e6
cc2268c
4927d16
cc2268c
4927d16
cc2268c
 
 
 
 
 
 
4927d16
 
 
 
 
 
6b5d290
cc2268c
4927d16
 
 
 
cc2268c
4927d16
 
 
 
 
 
68c84b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4927d16
8cca886
4927d16
 
 
 
68c84b8
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import streamlit as st
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from datetime import datetime

# Define emoji list
EMOJI_LIST = {
    4: "πŸŽ‚",
    6: "πŸ€",
    8: "πŸ„",
    10: "🍁",
    12: "πŸ‚",
    20: "πŸƒ",
    50: "πŸ’",
    100: "🌟"
}

# Define the dice types
DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]

# Define the default number of rolls
DEFAULT_ROLLS = 10

# Define a function to roll dice
def roll_dice(num_rolls, dice_type):
    rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
    return rolls

# Define a function to plot tokens
def plot_tokens(health_tokens, coin_tokens):
    fig = go.Figure()
    fig.add_trace(go.Scatter(x=list(range(1, len(health_tokens) + 1)), y=health_tokens, name="Health"))
    fig.add_trace(go.Scatter(x=list(range(1, len(coin_tokens) + 1)), y=coin_tokens, name="Coins"))
    fig.update_layout(title="Token Accumulation", xaxis_title="Rolls", yaxis_title="Tokens")
    st.plotly_chart(fig)

# Define the app
st.title("Dice Rolling Game")

# Get username
st.write("Enter your username:")
username = st.text_input("Username")

# Get number of rolls
st.write("Choose the number of rolls:")
num_rolls = st.slider("Number of Rolls", 1, 1000000, DEFAULT_ROLLS)

# Get dice types and roll dice
history = {}
for dice_type in DICE_TYPES:
    rolls = roll_dice(num_rolls, dice_type)
    st.write(f"Results for {dice_type}-sided dice:")
    for roll in rolls:
        st.write(f"{EMOJI_LIST[dice_type]} {roll}")
        if roll == dice_type:
            st.write("Congratulations! You rolled the highest value!")
            if dice_type == 100:
                st.write("Adding 10 coins for rolling over 90 on 100-sided dice.")
                if "coin_tokens" not in history:
                    history["coin_tokens"] = [0]
                history["coin_tokens"].append(history["coin_tokens"][-1] + 10)
    if "roll_history" not in history:
        history["roll_history"] = {}
    history["roll_history"][dice_type] = rolls

# Plot tokens
if "health_tokens" not in history:
    history["health_tokens"] = [0]
if "coin_tokens" not in history:
    history["coin_tokens"] = [0]
st.write("Token Accumulation:")
plot_tokens(history["health_tokens"], history["coin_tokens"])

# Save history to CSV file
timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
filename = f"{timestamp}.csv"
data = {"Username": [username], "Date": [timestamp], **history}

# Concatenate all roll histories into a single dictionary
all_rolls = {}
for dice_type, rolls in history["roll_history"].items():
    all_rolls[f"{dice_type}-sided dice"] = rolls
all_rolls = pd.DataFrame(all_rolls)

# Create a Series for each token type
health_tokens = pd.Series(history["health_tokens"], name="Health Tokens")
coin_tokens = pd.Series(history["coin_tokens"], name="Coin Tokens")

# Concatenate all data into a single DataFrame
df = pd.concat([all_rolls, health_tokens, coin_tokens], axis=1)

# Save history to CSV file
df.to_csv(filename, index=False)

# Show download link for CSV file
st.write("Download the dice rolling history:")
with open(filename, "rb") as f:
    bytes_data = f.read()