awacke1 commited on
Commit
8fdf672
Β·
1 Parent(s): 4bccfbe

Rename Backup-app-pyBeforeDownload.py to app_backup.py

Browse files
Backup-app-pyBeforeDownload.py β†’ app_backup.py RENAMED
@@ -5,61 +5,48 @@ import plotly.graph_objects as go
5
  from datetime import datetime
6
  from base64 import b64encode
7
 
8
- # Define emoji list
9
  EMOJI_LIST = {4: "πŸŽ‚", 6: "πŸ€", 8: "πŸ„", 10: "🍁", 12: "πŸ‚", 20: "πŸƒ", 50: "πŸ’", 100: "🌟"}
10
-
11
- # Define the dice types and default number of rolls
12
  DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
13
  DEFAULT_ROLLS = 3
14
 
15
- # Define a function to roll dice
16
  def roll_dice(num_rolls, dice_type):
17
  rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
18
  return rolls
19
 
20
- # Define a function to plot tokens
21
  def plot_tokens(health_tokens, coin_tokens):
22
  fig = go.Figure()
23
- fig.add_trace(go.Scatter(x=list(range(1, len(health_tokens) + 1)), y=health_tokens, name="Health"))
24
- fig.add_trace(go.Scatter(x=list(range(1, len(coin_tokens) + 1)), y=coin_tokens, name="Coins"))
25
  fig.update_layout(title="Token Accumulation", xaxis_title="Rolls", yaxis_title="Tokens")
26
  st.plotly_chart(fig)
27
 
28
- # Define the app
29
- st.title("Dice Rolling Game")
30
-
31
- # Get username and number of rolls
32
- username = st.text_input("Enter your username:")
33
- num_rolls = st.slider("Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
34
 
35
- # Roll dice for each type and accumulate high rolls and tokens
36
  history = {"health_tokens": [0], "coin_tokens": [0]}
37
  for dice_type in DICE_TYPES:
38
  rolls = roll_dice(num_rolls, dice_type)
39
  highest_rolls = sum(roll == dice_type for roll in rolls)
40
- st.write(f"Results for {dice_type}-sided dice:")
 
 
41
  for roll in rolls:
42
- st.write(f"{EMOJI_LIST[dice_type]} {roll}")
43
  if roll == dice_type:
44
- st.write("Congratulations! You rolled the highest value!")
 
 
 
45
  if dice_type == 100:
46
- st.write("Adding 10 coins for rolling over 90 on 100-sided dice.")
47
- history["coin_tokens"].append(history["coin_tokens"][-1] + 10)
48
  history[f"{dice_type}-sided dice high rolls"] = highest_rolls
49
  history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
50
- history["health_tokens"].append(history.get("20-sided dice high rolls", 0))
51
- history["coin_tokens"].append(history.get("100-sided dice high rolls", 0))
52
-
53
- # Plot token accumulation
54
- st.write("Token Accumulation:")
55
  plot_tokens(history["health_tokens"], history["coin_tokens"])
56
-
57
- # Create DataFrame and save to CSV file
58
  df = pd.concat([pd.DataFrame(history["roll_history"]), pd.DataFrame(history["health_tokens"], columns=["Health Tokens"]), pd.DataFrame(history["coin_tokens"], columns=["Coin Tokens"])], axis=1)
59
  timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
60
  filename = f"{username}_{timestamp}.csv"
61
  df.to_csv(filename, index=False)
62
-
63
- # Show download link for CSV file
64
  st.markdown(f'<a href="data:file/csv;base64,{b64encode(open(filename, "rb").read()).decode()}" download="{filename}">Download CSV File</a>', unsafe_allow_html=True)
65
-
 
5
  from datetime import datetime
6
  from base64 import b64encode
7
 
 
8
  EMOJI_LIST = {4: "πŸŽ‚", 6: "πŸ€", 8: "πŸ„", 10: "🍁", 12: "πŸ‚", 20: "πŸƒ", 50: "πŸ’", 100: "🌟"}
 
 
9
  DICE_TYPES = [4, 6, 8, 10, 12, 20, 50, 100]
10
  DEFAULT_ROLLS = 3
11
 
 
12
  def roll_dice(num_rolls, dice_type):
13
  rolls = np.random.randint(1, dice_type + 1, size=num_rolls)
14
  return rolls
15
 
 
16
  def plot_tokens(health_tokens, coin_tokens):
17
  fig = go.Figure()
18
+ fig.add_trace(go.Scatter(x=list(range(1, len(health_tokens) + 1)), y=health_tokens, name="πŸ’– Health"))
19
+ fig.add_trace(go.Scatter(x=list(range(1, len(coin_tokens) + 1)), y=coin_tokens, name="πŸ’° Coins"))
20
  fig.update_layout(title="Token Accumulation", xaxis_title="Rolls", yaxis_title="Tokens")
21
  st.plotly_chart(fig)
22
 
23
+ st.title("🎲 Dice Rolling Game")
24
+ username = st.text_input("πŸ‘€ Enter your username:")
25
+ num_rolls = st.slider("πŸ”’ Choose the number of rolls:", 1, 100, DEFAULT_ROLLS)
 
 
 
26
 
 
27
  history = {"health_tokens": [0], "coin_tokens": [0]}
28
  for dice_type in DICE_TYPES:
29
  rolls = roll_dice(num_rolls, dice_type)
30
  highest_rolls = sum(roll == dice_type for roll in rolls)
31
+ coin_tokens_added = 0
32
+ dice_results = [f"{EMOJI_LIST[dice_type]} {roll}" for roll in rolls]
33
+ st.write(f"🎲 Results for {dice_type}-sided dice: {' | '.join(dice_results)}")
34
  for roll in rolls:
 
35
  if roll == dice_type:
36
+ st.write(f"πŸŽ‰ Congratulations! You rolled the {EMOJI_LIST[dice_type]} highest value! πŸ’° Adding 3 coins.")
37
+ coin_tokens_added += 3
38
+ if roll == max(rolls):
39
+ st.write(f"πŸŽ‰ Congratulations! You rolled the {EMOJI_LIST[dice_type]} maximum value! πŸ’– Adding 10 health tokens.")
40
  if dice_type == 100:
41
+ history["health_tokens"].append(history["health_tokens"][-1] + 10)
 
42
  history[f"{dice_type}-sided dice high rolls"] = highest_rolls
43
  history["roll_history"] = {**history.get("roll_history", {}), dice_type: rolls}
44
+ history["coin_tokens"].append(history["coin_tokens"][-1] + coin_tokens_added)
45
+
46
+ st.write("πŸ’°πŸ’– Token Accumulation:")
 
 
47
  plot_tokens(history["health_tokens"], history["coin_tokens"])
 
 
48
  df = pd.concat([pd.DataFrame(history["roll_history"]), pd.DataFrame(history["health_tokens"], columns=["Health Tokens"]), pd.DataFrame(history["coin_tokens"], columns=["Coin Tokens"])], axis=1)
49
  timestamp = datetime.now().strftime("%m-%d-%Y-%H-%M-%S")
50
  filename = f"{username}_{timestamp}.csv"
51
  df.to_csv(filename, index=False)
 
 
52
  st.markdown(f'<a href="data:file/csv;base64,{b64encode(open(filename, "rb").read()).decode()}" download="{filename}">Download CSV File</a>', unsafe_allow_html=True)