Spaces:
Runtime error
Runtime error
| 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.") | |
| 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() | |