awacke1's picture
Update app.py
ddff327
raw
history blame
8.75 kB
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()