Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import random | |
| st.set_page_config(page_title="๐ฎ Mini Game Arcade", page_icon="๐ฒ") | |
| st.title("๐ฎ Mini Game Arcade") | |
| # Game selection | |
| game = st.selectbox("Choose a game to play:", [ | |
| "Rock, Paper, Scissors", | |
| "Guess the Number", | |
| "Word Scramble", | |
| "Emoji Quiz", | |
| "Math Quiz", | |
| "Hangman", | |
| "Tic-Tac-Toe", | |
| "Coin Toss", | |
| "Dice Roll", | |
| "Memory Challenge" | |
| ]) | |
| # ------------------------------ | |
| if game == "Rock, Paper, Scissors": | |
| st.subheader("โโโ๏ธ Rock, Paper, Scissors") | |
| user_choice = st.radio("Choose:", ["Rock", "Paper", "Scissors"]) | |
| if st.button("Play"): | |
| computer_choice = random.choice(["Rock", "Paper", "Scissors"]) | |
| st.write(f"Computer chose: **{computer_choice}**") | |
| if user_choice == computer_choice: | |
| st.info("It's a tie!") | |
| elif (user_choice, computer_choice) in [("Rock", "Scissors"), ("Scissors", "Paper"), ("Paper", "Rock")]: | |
| st.success("You win!") | |
| else: | |
| st.error("You lose!") | |
| # ------------------------------ | |
| elif game == "Guess the Number": | |
| st.subheader("๐ข Guess the Number (1-10)") | |
| secret = random.randint(1, 10) | |
| guess = st.number_input("Your guess:", 1, 10, step=1) | |
| if st.button("Check"): | |
| if guess == secret: | |
| st.success("๐ Correct! You guessed it.") | |
| else: | |
| st.warning(f"Wrong! The number was {secret}.") | |
| # ------------------------------ | |
| elif game == "Word Scramble": | |
| st.subheader("๐ค Word Scramble") | |
| word = random.choice(["streamlit", "python", "arcade", "developer", "career"]) | |
| scrambled = "".join(random.sample(word, len(word))) | |
| answer = st.text_input(f"Unscramble this word: **{scrambled}**") | |
| if st.button("Check"): | |
| if answer.lower() == word: | |
| st.success("โ Correct!") | |
| else: | |
| st.error(f"โ Wrong! The word was: **{word}**") | |
| # ------------------------------ | |
| elif game == "Emoji Quiz": | |
| st.subheader("๐ Emoji Quiz") | |
| quiz = { | |
| "๐ฆ๐": "lion king", | |
| "๐๐ฑ": "apple", | |
| "๐ฌ๐ฟ": "movie", | |
| "โฝ๐": "football", | |
| } | |
| emoji, answer = random.choice(list(quiz.items())) | |
| user_answer = st.text_input(f"What does this mean? {emoji}") | |
| if st.button("Submit"): | |
| if user_answer.lower() == answer: | |
| st.success("Correct! ๐") | |
| else: | |
| st.error(f"Nope! The answer was: {answer}") | |
| # ------------------------------ | |
| elif game == "Math Quiz": | |
| st.subheader("โ Math Quiz") | |
| a, b = random.randint(1, 20), random.randint(1, 20) | |
| user_answer = st.number_input(f"What is {a} + {b}?", value=0) | |
| if st.button("Check Answer"): | |
| if user_answer == a+b: | |
| st.success("โ Correct!") | |
| else: | |
| st.error(f"โ Wrong! Answer is {a+b}.") | |
| # ------------------------------ | |
| elif game == "Hangman": | |
| st.subheader("๐ชข Hangman (1 chance)") | |
| word = random.choice(["cat", "dog", "bat", "rat", "sun"]) | |
| display = "_ " * len(word) | |
| guess = st.text_input(f"Guess the word: {display}").lower() | |
| if st.button("Submit Guess"): | |
| if guess == word: | |
| st.success("๐ You win!") | |
| else: | |
| st.error(f"You lose! Word was: {word}") | |
| # ------------------------------ | |
| elif game == "Tic-Tac-Toe": | |
| st.subheader("โโญ Tic-Tac-Toe") | |
| st.write("Sorry! Tic-Tac-Toe is currently just a placeholder (implementing full board interaction is advanced here).") | |
| st.info("You can extend this by adding a 3x3 grid with session state!") | |
| # ------------------------------ | |
| elif game == "Coin Toss": | |
| st.subheader("๐ช Coin Toss") | |
| if st.button("Toss Coin"): | |
| result = random.choice(["Heads", "Tails"]) | |
| st.write(f"Result: **{result}**") | |
| # ------------------------------ | |
| elif game == "Dice Roll": | |
| st.subheader("๐ฒ Dice Roll") | |
| if st.button("Roll Dice"): | |
| roll = random.randint(1,6) | |
| st.write(f"You rolled: **{roll}**") | |
| # ------------------------------ | |
| elif game == "Memory Challenge": | |
| st.subheader("๐ง Memory Challenge") | |
| numbers = [random.randint(1, 9) for _ in range(3)] | |
| st.write(f"Remember this sequence: {numbers}") | |
| guess = st.text_input("Enter the sequence (comma-separated):") | |
| if st.button("Check Sequence"): | |
| if guess.replace(" ", "") == ",".join(map(str, numbers)): | |
| st.success("๐ Correct!") | |
| else: | |
| st.error(f"Wrong! It was: {numbers}") | |