Spaces:
Runtime error
Runtime error
Create backup.app.py
Browse files- backup.app.py +75 -0
backup.app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
PLAYERS = {
|
5 |
+
"Player 1": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 5, "Defense": 3},
|
6 |
+
"Player 2": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 4, "Defense": 4},
|
7 |
+
}
|
8 |
+
|
9 |
+
MONSTERS = {
|
10 |
+
"Goblin": {"Picture": "πΊ", "Description": "A small, mischievous creature with sharp teeth and claws.", "Attack": 2, "Defense": 1},
|
11 |
+
"Orc": {"Picture": "πΉ", "Description": "A large, brutish humanoid with green skin and a nasty temperament.", "Attack": 4, "Defense": 2},
|
12 |
+
"Dragon": {"Picture": "π²", "Description": "A massive, fire-breathing beast with scales as hard as steel.", "Attack": 6, "Defense": 5},
|
13 |
+
}
|
14 |
+
|
15 |
+
def get_random_monster():
|
16 |
+
monster_name = st.session_state.selected_monster
|
17 |
+
if monster_name:
|
18 |
+
monster = MONSTERS[monster_name]
|
19 |
+
st.write("Picture: ", monster["Picture"])
|
20 |
+
st.write("Description: ", monster["Description"])
|
21 |
+
st.write("Attack: ", monster["Attack"])
|
22 |
+
st.write("Defense: ", monster["Defense"])
|
23 |
+
return monster
|
24 |
+
else:
|
25 |
+
return None
|
26 |
+
|
27 |
+
def save_data():
|
28 |
+
data = pd.DataFrame.from_dict(st.session_state.players, orient="index")
|
29 |
+
filename = "player_data.csv"
|
30 |
+
data.to_csv(filename)
|
31 |
+
st.write(f"Player data saved to {filename}")
|
32 |
+
|
33 |
+
def display_player_card(player_name, player_data):
|
34 |
+
st.write(f"**{player_name}**")
|
35 |
+
for key, value in player_data.items():
|
36 |
+
st.write(f"{key}: {value}")
|
37 |
+
|
38 |
+
def battle_player_card():
|
39 |
+
selected_player = st.session_state.selected_player
|
40 |
+
selected_monster = st.session_state.selected_monster
|
41 |
+
if not selected_player:
|
42 |
+
st.warning("Please select a player card.")
|
43 |
+
return
|
44 |
+
if not selected_monster:
|
45 |
+
st.warning("Please select a monster.")
|
46 |
+
return
|
47 |
+
player_data = PLAYERS[selected_player]
|
48 |
+
monster_data = MONSTERS[selected_monster]
|
49 |
+
if player_data["Attack"] > monster_data["Defense"]:
|
50 |
+
st.success("You defeated the monster!")
|
51 |
+
else:
|
52 |
+
st.error("The monster defeated you.")
|
53 |
+
save_data()
|
54 |
+
|
55 |
+
def main():
|
56 |
+
st.set_page_config(page_title="Player Cards and Monsters")
|
57 |
+
st.title("Player Cards and Monsters")
|
58 |
+
st.write("π Select a player card to reveal a monster and battle it! π")
|
59 |
+
|
60 |
+
if "players" not in st.session_state:
|
61 |
+
st.session_state.players = {}
|
62 |
+
|
63 |
+
st.sidebar.title("π Select a Player Card")
|
64 |
+
selected_player = st.sidebar.radio("Select a player:", list(PLAYERS.keys()))
|
65 |
+
display_player_card(selected_player, PLAYERS[selected_player])
|
66 |
+
|
67 |
+
if st.button("π₯ Battle!"):
|
68 |
+
st.session_state.selected_player = selected_player
|
69 |
+
st.session_state.selected_monster = st.sidebar.selectbox("Select a monster:", list(MONSTERS.keys()))
|
70 |
+
monster = get_random_monster()
|
71 |
+
if monster:
|
72 |
+
battle_player_card()
|
73 |
+
|
74 |
+
if __name__ == "__main__":
|
75 |
+
main()
|