taggdaniel/htmlelementtrumps
0
1import streamlit as st2import pandas as pd3import numpy as np4 5# Load Excel file and read data6file_path = '/mnt/data/Element Top Trumps 2nd page reversed 2021.xlsx'7xl = pd.ExcelFile(file_path)8sheet_name = 'Top Trump Cards'9data = pd.read_excel(file_path, sheet_name=sheet_name, header=None)10 11# Function to extract card data based on given ranges12def extract_card_data(df, start_row, start_col, rows, cols):13 return df.iloc[start_row:start_row + rows, start_col:start_col + cols]14 15# Extract front and rear card data for Hydrogen as an example16front_card = extract_card_data(data, 1, 1, 28, 5) # B2:F29 for front card17rear_card = extract_card_data(data, 1, 16, 28, 5) # Q2:U29 for rear card18 19# Function to extract card data for any element20def get_element_card_data(df, start_row, start_col_offset=0, rear_col_offset=15):21 front = extract_card_data(df, start_row, start_col_offset, 28, 5)22 rear = extract_card_data(df, start_row, start_col_offset + rear_col_offset, 28, 5)23 return front, rear24 25# Streamlit app layout26st.title("Periodic Table Top Trumps Multiplayer Game")27 28# Login functionality29if 'players' not in st.session_state:30 st.session_state.players = []31 32with st.sidebar:33 st.header("Player Login")34 username = st.text_input("Enter your name:")35 if st.button("Join Game"):36 if username and username not in st.session_state.players:37 st.session_state.players.append(username)38 st.success(f"{username} has joined the game!")39 elif username in st.session_state.players:40 st.warning("You are already in the game.")41 else:42 st.error("Please enter a valid name.")43 44# Display the players45st.subheader("Players in the Game")46if st.session_state.players:47 st.write(", ".join(st.session_state.players))48else:49 st.write("No players have joined yet.")50 51# Game joining and room management52st.sidebar.header("Game Room")53if len(st.session_state.players) > 1:54 if st.sidebar.button("Start Game"):55 st.session_state['game_started'] = True56 st.sidebar.success("Game has started!")57else:58 st.sidebar.info("At least 2 players are needed to start the game.")59 60# Display a sample front and rear card61st.subheader("Sample Element Card - Hydrogen")62col1, col2 = st.columns(2)63 64with col1:65 st.write("**Front of Card**")66 st.dataframe(front_card)67 68with col2:69 st.write("**Rear of Card (Hidden to other players)**")70 st.dataframe(rear_card)71 72# Display cards for different elements based on user selection73st.subheader("Select an Element")74element_row = st.slider("Choose element row (e.g., 1 for Hydrogen)", min_value=1, max_value=data.shape[0] // 30, step=1)75front_card, rear_card = get_element_card_data(data, (element_row - 1) * 30 + 1)76 77st.subheader("Selected Element Card")78col1, col2 = st.columns(2)79 80with col1:81 st.write("**Front of Card**")82 st.dataframe(front_card)83 84with col2:85 st.write("**Rear of Card (Hidden to other players)**")86 st.dataframe(rear_card)87 88st.info("Navigate through the periodic table to explore different element cards.")89 