Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,116 +1,122 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import
|
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 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import random
|
3 |
+
import csv
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Define the player card attributes
|
7 |
+
player_cards = {
|
8 |
+
"Player 1": {
|
9 |
+
"sketch": "๐ฉ",
|
10 |
+
"character": "Nurse",
|
11 |
+
"player_board": "๐ฅ",
|
12 |
+
"action_dice": "๐ฒ",
|
13 |
+
"health_tokens": "โค๏ธ",
|
14 |
+
"coin": "๐ฐ",
|
15 |
+
"battle_tokens": "โ๏ธ"
|
16 |
+
},
|
17 |
+
"Player 2": {
|
18 |
+
"sketch": "๐จ",
|
19 |
+
"character": "Doctor",
|
20 |
+
"player_board": "๐ฅ",
|
21 |
+
"action_dice": "๐ฒ",
|
22 |
+
"health_tokens": "โค๏ธ",
|
23 |
+
"coin": "๐ฐ",
|
24 |
+
"battle_tokens": "โ๏ธ"
|
25 |
+
}
|
26 |
+
}
|
27 |
+
|
28 |
+
# Define the health problems
|
29 |
+
health_problems = ["Flu", "COVID-19", "Diabetes", "Heart Disease", "Cancer"]
|
30 |
+
|
31 |
+
# Define the game rules
|
32 |
+
attack_range = (1, 20)
|
33 |
+
defense_range = (1, 10)
|
34 |
+
|
35 |
+
# Create a function to play a single round of the game
|
36 |
+
def play_round(player_card, health_problem):
|
37 |
+
st.write(f"{player_card['sketch']} {player_card['character']} attacks {health_problem} with {player_card['action_dice']}...")
|
38 |
+
attack_score = random.randint(*attack_range)
|
39 |
+
defense_score = random.randint(*defense_range)
|
40 |
+
health_ferocity = random.randint(*attack_range)
|
41 |
+
health_resistance = random.randint(*defense_range)
|
42 |
+
if attack_score > health_resistance:
|
43 |
+
st.write(f"{player_card['sketch']} {player_card['character']} deals {attack_score - health_resistance} damage to {health_problem}!")
|
44 |
+
else:
|
45 |
+
st.write(f"{player_card['sketch']} {player_card['character']} misses the attack!")
|
46 |
+
if health_ferocity > defense_score:
|
47 |
+
st.write(f"{health_problem} deals {health_ferocity - defense_score} damage to {player_card['sketch']} {player_card['character']}!")
|
48 |
+
else:
|
49 |
+
st.write(f"{health_problem} fails to attack!")
|
50 |
+
|
51 |
+
# Create a function to play multiple rounds of the game
|
52 |
+
def play_game(num_games):
|
53 |
+
# Initialize the game state
|
54 |
+
player_scores = {player: 0 for player in player_cards}
|
55 |
+
health_problem_scores = {problem: 0 for problem in health_problems}
|
56 |
+
for i in range(num_games):
|
57 |
+
# Randomly select a player and health problem
|
58 |
+
player = random.choice(list(player_cards.keys()))
|
59 |
+
health_problem = random.choice(health_problems)
|
60 |
+
# Play the round
|
61 |
+
play_round(player_cards[player], health_problem)
|
62 |
+
# Update the scores
|
63 |
+
player_scores[player] += 1
|
64 |
+
health_problem_scores[health_problem] += 1
|
65 |
+
# Save the game state to a CSV file
|
66 |
+
with open("game_state.csv", "a", newline="") as f:
|
67 |
+
writer = csv.writer(f)
|
68 |
+
if os.stat("game_state.csv").st_size == 0:
|
69 |
+
writer.writerow(["Player", "Sketch", "Character", "Player Board", "Action Dice", "Health Tokens", "Coin", "Battle Tokens", "Score"])
|
70 |
+
for player, attributes in player_cards.items():
|
71 |
+
row = [player, attributes["sketch"], attributes["character"], attributes["player_board"], attributes["action_dice"], attributes["health_tokens"], attributes["coin"], attributes["battle_tokens"], player_scores[player]]
|
72 |
+
writer.writerow(row)
|
73 |
+
for problem in health_problems:
|
74 |
+
row = [problem, health_problem_scores[problem]]
|
75 |
+
writer.writerow(row)
|
76 |
+
# Display the game results
|
77 |
+
st.write("# Game Results")
|
78 |
+
for player, score in player_scores.items():
|
79 |
+
st.write(f"{player}: {score} wins")
|
80 |
+
for problem, score in health_problem_scores.items():
|
81 |
+
st.write(f"{problem}: {score} defeats")
|
82 |
+
# Display a button to download the game state CSV file
|
83 |
+
if os.path.exists("game_state.csv"):
|
84 |
+
st.write("# Download Game State")
|
85 |
+
files = [f for f in os.listdir(".") if os.path.isfile(f) and f.endswith(".csv")]
|
86 |
+
if "game_state.csv" in files:
|
87 |
+
files.remove("game_state.csv")
|
88 |
+
if len(files) > 0:
|
89 |
+
file_to_delete = st.selectbox("Select a file to delete", files)
|
90 |
+
if st.button("Delete File"):
|
91 |
+
os.remove(file_to_delete)
|
92 |
+
if st.button("Download Game State"):
|
93 |
+
with open("game_state.csv", "r") as f:
|
94 |
+
csv_data = f.read()
|
95 |
+
st.download_button("game_state.csv", csv_data, file_name="game_state.csv", mime="text/csv")
|
96 |
+
st.write("*Note: Downloaded files are saved in your browser's default download location*")
|
97 |
+
|
98 |
+
# Define the Streamlit app
|
99 |
+
def app():
|
100 |
+
st.set_page_config(page_title="Health Care Game", page_icon="๐ฅ", layout="wide")
|
101 |
+
st.title("Health Care Game")
|
102 |
+
st.sidebar.write("# Game Settings")
|
103 |
+
num_games = st.sidebar.slider("Number of games to play", 1, 100, 10)
|
104 |
+
st.sidebar.write("# Player Cards")
|
105 |
+
for player, attributes in player_cards.items():
|
106 |
+
st.sidebar.write(f"## {player}")
|
107 |
+
st.sidebar.write(f"Sketch: {attributes['sketch']}")
|
108 |
+
st.sidebar.write(f"Character: {attributes['character']}")
|
109 |
+
st.sidebar.write(f"Player Board: {attributes['player_board']}")
|
110 |
+
st.sidebar.write(f"Action Dice: {attributes['action_dice']}")
|
111 |
+
st.sidebar.write(f"Health Tokens: {attributes['health_tokens']}")
|
112 |
+
st.sidebar.write(f"Coin: {attributes['coin']}")
|
113 |
+
st.sidebar.write(f"Battle Tokens: {attributes['battle_tokens']}")
|
114 |
+
st.sidebar.write("# Health Problems")
|
115 |
+
for problem in health_problems:
|
116 |
+
st.sidebar.write(f"- {problem}")
|
117 |
+
# Start the game when the user clicks the "Play Game" button
|
118 |
+
if st.button("Play Game"):
|
119 |
+
play_game(num_games)
|
120 |
+
|
121 |
+
if __name__ == "__main__":
|
122 |
+
app()
|