import streamlit as st import random st.set_page_config(page_title="Mini Game Arcade 🎮", layout="centered") # ---------- CSS for Block Buttons ---------- st.markdown(""" """, unsafe_allow_html=True) # ---------- Title and Intro ---------- st.title("🎮 Mini Game Arcade") st.markdown("Choose a game below and start playing! Score will be tracked across session runtime.") # ---------- Score Tracker ---------- if "score" not in st.session_state: st.session_state.score = 0 st.sidebar.header("đŸŽ¯ Your Score") st.sidebar.success(f"Total Score: {st.session_state.score}") # ---------- Game Options ---------- games = { "Rock Paper Scissors âœŠâœ‹âœŒī¸": "rps", "Guess the Number đŸ”ĸ": "guess", "Word Scramble 🔤": "scramble", "Emoji Quiz 😊": "emoji", "Math Challenge âž•âž–âœ–ī¸âž—": "math", "Hangman 🔠": "hangman", "Flag Guess 🌍": "flag", "Capital Quiz đŸ›ī¸": "capital", "Riddle Me 🧠": "riddle", "Color Match 🎨": "color", "Quick Reaction âąī¸": "reaction", "Memory Match 🧩": "memory", "Odd One Out 🤔": "odd", "Animal Sound Guess 🐾": "sound", "Typing Speed Test âŒ¨ī¸": "typing" } # ---------- Block Button Layout ---------- st.markdown("### đŸ•šī¸ Pick a Game:") game_keys = list(games.keys()) selected_game = None for i in range(0, len(game_keys), 3): row = st.columns(3) for j in range(3): if i + j < len(game_keys): game_name = game_keys[i + j] key = games[game_name] if row[j].button(game_name, key=f"btn_{key}"): selected_game = key # ---------- Game Implementations ---------- def rock_paper_scissors(): st.header("Rock Paper Scissors") options = ["Rock", "Paper", "Scissors"] user_choice = st.radio("Choose your move:", options, horizontal=True) if st.button("Play"): comp_choice = random.choice(options) st.write(f"🤖 Computer chose: {comp_choice}") if user_choice == comp_choice: st.info("It's a draw!") elif (user_choice == "Rock" and comp_choice == "Scissors") or \ (user_choice == "Paper" and comp_choice == "Rock") or \ (user_choice == "Scissors" and comp_choice == "Paper"): st.success("You win!") st.session_state.score += 1 else: st.error("You lose!") def guess_the_number(): st.header("Guess the Number") if "number" not in st.session_state: st.session_state.number = random.randint(1, 20) guess = st.number_input("Guess a number between 1 and 20", min_value=1, max_value=20, step=1) if st.button("Submit Guess"): if guess == st.session_state.number: st.success("Correct! 🎉") st.session_state.score += 1 st.session_state.number = random.randint(1, 20) elif guess < st.session_state.number: st.info("Too low!") else: st.info("Too high!") def word_scramble(): st.header("Word Scramble") words = ["streamlit", "arcade", "python", "huggingface", "interface"] if "scramble_word" not in st.session_state: word = random.choice(words) st.session_state.scramble_word = word st.session_state.scrambled = ''.join(random.sample(word, len(word))) st.write(f"Unscramble this word: **{st.session_state.scrambled}**") user_input = st.text_input("Your answer:") if st.button("Check Word"): if user_input.lower() == st.session_state.scramble_word: st.success("Correct!") st.session_state.score += 1 del st.session_state.scramble_word del st.session_state.scrambled else: st.error("Wrong guess!") def emoji_quiz(): st.header("Emoji Quiz") emojis = { "🍕đŸĸ": "ninjaturtle", "â„ī¸â›„": "frozen", "🚀🌕": "moonlanding", "đŸĻ‡đŸĻ¸â€â™‚ī¸": "batman", "🐍đŸ’ģ": "python" } question, answer = random.choice(list(emojis.items())) st.write(f"Guess the word/phrase: {question}") user_ans = st.text_input("Your answer:") if st.button("Submit"): if user_ans.lower().replace(" ", "") == answer: st.success("Correct!") st.session_state.score += 1 else: st.error("Nope, try again!") def math_challenge(): st.header("Math Challenge") a = random.randint(1, 20) b = random.randint(1, 20) op = random.choice(["+", "-", "*"]) correct = eval(f"{a}{op}{b}") st.write(f"Solve: **{a} {op} {b} = ?**") ans = st.number_input("Your answer:", step=1) if st.button("Check Answer"): if ans == correct: st.success("Correct!") st.session_state.score += 1 else: st.error(f"Wrong! Correct answer was {correct}") def hangman(): st.header("Hangman 🔠") st.info("Coming soon! Classic hangman challenge.") def flag_guess(): st.header("Flag Guess 🌍") st.info("Guess the country based on the flag! (images can be added)") def capital_quiz(): st.header("Capital Quiz đŸ›ī¸") st.info("What is the capital of France? (example: Paris)") def riddle_me(): st.header("Riddle Me 🧠") st.info("I speak without a mouth and hear without ears. What am I?") def color_match(): st.header("Color Match 🎨") st.info("Match the color name to the correct swatch!") def quick_reaction(): st.header("Quick Reaction âąī¸") st.info("Click the button as fast as you can when it turns green!") def memory_match(): st.header("Memory Match 🧩") st.info("Remember the sequence of emojis!") def odd_one_out(): st.header("Odd One Out 🤔") st.info("Which item doesn't belong: Apple, Banana, Carrot?") def animal_sound_guess(): st.header("Animal Sound Guess 🐾") st.info("Guess the animal from the sound (playable audio coming soon).") def typing_speed_test(): st.header("Typing Speed Test âŒ¨ī¸") st.info("Type the following sentence as fast as possible!") # ---------- Run Selected Game ---------- if selected_game == "rps": rock_paper_scissors() elif selected_game == "guess": guess_the_number() elif selected_game == "scramble": word_scramble() elif selected_game == "emoji": emoji_quiz() elif selected_game == "math": math_challenge() elif selected_game == "hangman": hangman() elif selected_game == "flag": flag_guess() elif selected_game == "capital": capital_quiz() elif selected_game == "riddle": riddle_me() elif selected_game == "color": color_match() elif selected_game == "reaction": quick_reaction() elif selected_game == "memory": memory_match() elif selected_game == "odd": odd_one_out() elif selected_game == "sound": animal_sound_guess() elif selected_game == "typing": typing_speed_test() # ---------- Footer ---------- st.markdown("---") st.markdown("Made with â¤ī¸ using Streamlit. Add more games to keep it fun!")