Spaces:
Sleeping
Sleeping
File size: 2,402 Bytes
6874af4 |
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 |
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)
|