Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="Mini Game Arcade", layout="wide")
|
| 5 |
+
st.markdown("<style> body { background-color: #ffffff; } </style>", unsafe_allow_html=True)
|
| 6 |
+
|
| 7 |
+
# Inject CSS to style left column
|
| 8 |
+
st.markdown("""
|
| 9 |
+
<style>
|
| 10 |
+
.left-box {
|
| 11 |
+
background-color: #f5f6fa;
|
| 12 |
+
padding: 20px;
|
| 13 |
+
border-radius: 10px;
|
| 14 |
+
height: 100%;
|
| 15 |
+
}
|
| 16 |
+
.stButton>button {
|
| 17 |
+
width: 100%;
|
| 18 |
+
margin-bottom: 10px;
|
| 19 |
+
}
|
| 20 |
+
</style>
|
| 21 |
+
""", unsafe_allow_html=True)
|
| 22 |
+
|
| 23 |
+
st.markdown("## 🎮 Mini Game Arcade")
|
| 24 |
+
|
| 25 |
+
# --- Game Titles ---
|
| 26 |
+
game_list = [
|
| 27 |
+
"Rock Paper Scissors",
|
| 28 |
+
"Guess the Number",
|
| 29 |
+
"Word Scramble",
|
| 30 |
+
"Emoji Quiz",
|
| 31 |
+
"Score Tracker",
|
| 32 |
+
"Dice Roller",
|
| 33 |
+
"Coin Toss",
|
| 34 |
+
"Math Quiz",
|
| 35 |
+
"Hangman",
|
| 36 |
+
"Color Guess"
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
# --- Layout Columns ---
|
| 40 |
+
left_col, right_col = st.columns([1, 2])
|
| 41 |
+
selected_game = None
|
| 42 |
+
|
| 43 |
+
# --- Left: Game Selection (with background) ---
|
| 44 |
+
with left_col:
|
| 45 |
+
st.markdown('<div class="left-box">', unsafe_allow_html=True)
|
| 46 |
+
st.subheader("🕹️ Choose a Game")
|
| 47 |
+
for game_name in game_list:
|
| 48 |
+
if st.button(game_name, key=game_name):
|
| 49 |
+
selected_game = game_name
|
| 50 |
+
st.session_state["selected_game"] = selected_game
|
| 51 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 52 |
+
|
| 53 |
+
# Keep selection across reruns
|
| 54 |
+
if "selected_game" in st.session_state:
|
| 55 |
+
selected_game = st.session_state["selected_game"]
|
| 56 |
+
|
| 57 |
+
# --- Right: Game Area ---
|
| 58 |
+
with right_col:
|
| 59 |
+
if not selected_game:
|
| 60 |
+
st.info("👈 Select a game from the left to start playing.")
|
| 61 |
+
elif selected_game == "Rock Paper Scissors":
|
| 62 |
+
st.header("🪨📄✂️ Rock Paper Scissors")
|
| 63 |
+
options = ["Rock", "Paper", "Scissors"]
|
| 64 |
+
user_choice = st.selectbox("Choose your move:", options)
|
| 65 |
+
if st.button("Play"):
|
| 66 |
+
ai_choice = random.choice(options)
|
| 67 |
+
st.write(f"Computer chose: {ai_choice}")
|
| 68 |
+
if user_choice == ai_choice:
|
| 69 |
+
st.success("It's a tie!")
|
| 70 |
+
elif (user_choice == "Rock" and ai_choice == "Scissors") or \
|
| 71 |
+
(user_choice == "Paper" and ai_choice == "Rock") or \
|
| 72 |
+
(user_choice == "Scissors" and ai_choice == "Paper"):
|
| 73 |
+
st.success("You win!")
|
| 74 |
+
else:
|
| 75 |
+
st.error("You lose!")
|
| 76 |
+
|
| 77 |
+
# Add remaining games here as before...
|
| 78 |
+
# (Guess the Number, Word Scramble, etc. — same logic as before)
|