Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import random | |
| st.set_page_config(page_title="Mini Game Arcade", layout="wide") | |
| st.markdown("<style> body { background-color: #ffffff; } </style>", unsafe_allow_html=True) | |
| # Inject CSS to style left column | |
| st.markdown(""" | |
| <style> | |
| .left-box { | |
| background-color: #f5f6fa; | |
| padding: 20px; | |
| border-radius: 10px; | |
| height: 100%; | |
| } | |
| .stButton>button { | |
| width: 100%; | |
| margin-bottom: 10px; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| st.markdown("## ๐ฎ Mini Game Arcade") | |
| # --- Game Titles --- | |
| game_list = [ | |
| "Rock Paper Scissors", | |
| "Guess the Number", | |
| "Word Scramble", | |
| "Emoji Quiz", | |
| "Score Tracker", | |
| "Dice Roller", | |
| "Coin Toss", | |
| "Math Quiz", | |
| "Hangman", | |
| "Color Guess" | |
| ] | |
| # --- Layout Columns --- | |
| left_col, right_col = st.columns([1, 2]) | |
| selected_game = None | |
| # --- Left: Game Selection (with background) --- | |
| with left_col: | |
| st.markdown('<div class="left-box">', unsafe_allow_html=True) | |
| st.subheader("๐น๏ธ Choose a Game") | |
| for game_name in game_list: | |
| if st.button(game_name, key=game_name): | |
| selected_game = game_name | |
| st.session_state["selected_game"] = selected_game | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # Keep selection across reruns | |
| if "selected_game" in st.session_state: | |
| selected_game = st.session_state["selected_game"] | |
| # --- Right: Game Area --- | |
| with right_col: | |
| if not selected_game: | |
| st.info("๐ Select a game from the left to start playing.") | |
| elif selected_game == "Rock Paper Scissors": | |
| st.header("๐ชจ๐โ๏ธ Rock Paper Scissors") | |
| options = ["Rock", "Paper", "Scissors"] | |
| user_choice = st.selectbox("Choose your move:", options) | |
| if st.button("Play"): | |
| ai_choice = random.choice(options) | |
| st.write(f"Computer chose: {ai_choice}") | |
| if user_choice == ai_choice: | |
| st.success("It's a tie!") | |
| elif (user_choice == "Rock" and ai_choice == "Scissors") or \ | |
| (user_choice == "Paper" and ai_choice == "Rock") or \ | |
| (user_choice == "Scissors" and ai_choice == "Paper"): | |
| st.success("You win!") | |
| else: | |
| st.error("You lose!") | |
| # Add remaining games here as before... | |
| # (Guess the Number, Word Scramble, etc. โ same logic as before) | |