Spaces:
Runtime error
Runtime error
File size: 8,751 Bytes
71c8f6e 75b4491 6eec04b 62d058e 71c8f6e 1f61cb7 71c8f6e 1f61cb7 71c8f6e 1f61cb7 71c8f6e 3188d86 6c20dad 10f8eb4 6c20dad 71c8f6e 56cb16d 71c8f6e c7ff268 ea4ccf8 c7ff268 3188d86 ea0f961 c7ff268 14272ba c7ff268 75b4491 6eec04b 82189a4 56cb16d 71c8f6e 82189a4 f51e7e6 ea4ccf8 82189a4 75b4491 71c8f6e |
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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import os
import random
PLAYERS = {
"Player 1": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 5, "Defense": 3, "Class": "Wizard"},
"Player 2": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 4, "Defense": 4, "Class": "Fighter"},
"Player 3": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 3, "Defense": 5, "Class": "Ranger"},
"Player 4": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 4, "Defense": 4, "Class": "Rogue"},
"Player 5": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 2, "Defense": 6, "Class": "Cleric"},
"Player 6": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 3, "Defense": 5, "Class": "Barbarian"},
"Player 7": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 1, "Defense": 7, "Class": "Paladin"},
"Player 8": {"Sketch": "π¨", "Character": "π§ββοΈ", "Player Board": "π", "Action Dice": "π²", "Health Tokens": "β€οΈ", "Coin Tokens": "π°", "Battle Tokens": "βοΈ", "Attack": 2, "Defense": 6, "Class": "Bard"}
}
MONSTERS = {
"Goblin": {"Picture": "πΊ", "Description": "A small, mischievous creature with sharp teeth and claws.", "Attack": 2, "Defense": 1},
"Orc": {"Picture": "πΉ", "Description": "A large, brutish humanoid with green skin and a nasty temperament.", "Attack": 4, "Defense": 2},
"Dragon": {"Picture": "π²", "Description": "A massive, fire-breathing beast with scales as hard as steel.", "Attack": 6, "Defense": 5},
"Cyclops": {"Picture": "ποΈ", "Description": "A one-eyed giant with incredible strength.", "Attack": 8, "Defense": 6},
"Minotaur": {"Picture": "π", "Description": "A half-man, half-bull creature with a fierce temper.", "Attack": 5, "Defense": 3},
"Medusa": {"Picture": "π", "Description": "A woman with snakes for hair who can turn people to stone with her gaze.", "Attack": 3, "Defense": 2},
"Siren": {"Picture": "π§", "Description": "A beautiful creature with the upper body of a woman and the lower body of a bird, whose singing lures sailors to their doom.", "Attack": 1, "Defense": 1},
"Kraken": {"Picture": "π¦", "Description": "A massive sea creature with tentacles that can crush ships.", "Attack": 7, "Defense": 4},
"Beholder": {"Picture": "ποΈβπ¨οΈ", "Description": "A floating orb covered in eyes, each of which can cast a deadly spell.", "Attack": 9, "Defense": 8},
"Chimera": {"Picture": "π²ππ¦", "Description": "A creature with the body of a lion, the head of a goat, and the tail of a dragon.", "Attack": 6, "Defense": 5},
"Basilisk": {"Picture": "πποΈ", "Description": "A serpent that can turn people to stone with its gaze.", "Attack": 4, "Defense": 3},
"Mimic": {"Picture": "π¦", "Description": "A creature that can disguise itself as a treasure chest and surprise unwary adventurers.", "Attack": 2, "Defense": 1},
"Aboleth": {"Picture": "π¦ποΈ", "Description": "A sea monster with slimy tentacles and the power to control people's minds.", "Attack": 7, "Defense": 6},
"Troll": {"Picture": "πΉπ¨", "Description": "A regenerating monster that can only be killed with fire or acid.", "Attack": 5, "Defense": 4},
"Gorgon": {"Picture": "πποΈβπ¨οΈ", "Description": "A creature with the body of a lion and the head of a snake, whose gaze can turn people to stone.", "Attack": 6, "Defense": 4},
}
def shuffle_monsters():
global MONSTERS
keys = list(MONSTERS.keys())
random.shuffle(keys)
shuffled = {}
for key in keys:
shuffled[key] = MONSTERS[key]
MONSTERS = shuffled
def get_random_monster():
# Select a random monster based on its size
monster_sizes = [monster_data["Attack"] + monster_data["Defense"] for monster_data in MONSTERS.values()]
selected_size = random.choice(monster_sizes)
monster_names = [monster_name for monster_name, monster_data in MONSTERS.items() if monster_data["Attack"] + monster_data["Defense"] == selected_size]
selected_monster = random.choice(monster_names)
st.session_state.selected_monster = selected_monster
monster = MONSTERS[selected_monster]
st.write("Picture: ", monster["Picture"])
st.write("Description: ", monster["Description"])
st.write("Attack: ", monster["Attack"])
st.write("Defense: ", monster["Defense"])
return monster
def save_data():
data = pd.DataFrame.from_dict(st.session_state.players, orient="index")
filename = "player_data.csv"
data.to_csv(filename)
st.write(f"Player data saved to {filename}")
#def display_player_card(player_name, player_data):
# st.write(f"**{player_name}**")
# for key, value in player_data.items():
# st.write(f"{key}: {value}")
def battle_player_card():
selected_player = st.session_state.selected_player
#selected_monster = st.session_state.selected_monster
selected_monster = st.session_state.selected_monster
if not selected_player:
st.warning("Please select a player card.")
return
if not selected_monster:
st.warning("Please select a monster.")
return
player_data = PLAYERS[selected_player]
shuffle_monsters()
#monster_data = MONSTERS[selected_monster]
monster_data = selected_monster
if player_data["Attack"] > monster_data["Defense"]:
st.success("You defeated the monster!")
# Increase player's Health Tokens
# player_data["Health Tokens"] += 1
# Increase player's Health Tokens and add an additional heart emoji
player_data["Health Tokens"] += "β€οΈ"
else:
st.error("The monster defeated you.")
save_data()
def load_and_display_player_data():
if os.path.exists("player_data.csv"):
player_data = pd.read_csv("player_data.csv")
st.write("## Player Data")
st.write(player_data)
else:
st.write("Player data file not found.")
@st.experimental_singleton
def get_history():
return []
def display_player_card(player_name, player_data):
st.write(f"{player_name} {player_data['Sketch']} {player_data['Character']} {player_data['Player Board']} {player_data['Action Dice']} {player_data['Health Tokens']}β€οΈ {player_data['Coin Tokens']} {player_data['Battle Tokens']} {player_data['Class']} Attack: {player_data['Attack']} Defense: {player_data['Defense']}")
def main():
st.set_page_config(page_title="Player Cards and Monsters")
st.title("Player Cards and Monsters")
st.write("π Select a player card to reveal a monster and battle it! π")
if "players" not in st.session_state:
st.session_state.players = {}
history = get_history()
st.sidebar.title("π Select a Player Card")
selected_player = st.sidebar.radio("Select a player:", list(PLAYERS.keys()))
display_player_card(selected_player, PLAYERS[selected_player])
if st.button("π₯ Battle!"):
st.session_state.selected_player = selected_player
shuffle_monsters()
st.session_state.selected_monster = st.sidebar.selectbox("Select a monster:", list(MONSTERS.keys()))
monster = get_random_monster()
st.session_state.selected_monster = get_random_monster()
if monster:
battle_player_card()
history.append({"Player": selected_player, "Monster": st.session_state.selected_monster})
save_data()
else:
st.write("No monsters to battle. Please add more monsters to the MONSTERS dictionary.")
load_and_display_player_data()
st.write("## Battle History")
if history:
df = pd.DataFrame(history)
st.write(df)
else:
st.write("No battles fought yet.")
if __name__ == "__main__":
main()
|