Spaces:
Sleeping
Sleeping
File size: 4,480 Bytes
fdfffce |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
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}")
|