FaizaRiaz's picture
Create app.py
6d60025 verified
import streamlit as st
import random
# Title
st.title("🎮 Mini Game Arcade")
# Sidebar Menu
game = st.sidebar.selectbox(
"Choose a Game",
[
"Rock Paper Scissors",
"Guess the Number",
"Word Scramble",
"Emoji Quiz",
"Score Tracker",
"Dice Roller",
"Coin Toss",
"Math Quiz",
"Hangman",
"Color Guess"
]
)
# Rock Paper Scissors
if 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!")
# Guess the Number
elif game == "Guess the Number":
st.header("🔢 Guess the Number")
number = random.randint(1, 100)
guess = st.number_input("Guess a number between 1 and 100:", 1, 100)
if st.button("Check"):
if guess == number:
st.success("Correct! 🎉")
elif guess < number:
st.info("Try higher!")
else:
st.info("Try lower!")
# Word Scramble
elif game == "Word Scramble":
st.header("🔤 Word Scramble")
words = ["streamlit", "python", "arcade", "game", "computer"]
word = random.choice(words)
scrambled = "".join(random.sample(word, len(word)))
st.write(f"Scrambled word: {scrambled}")
user_guess = st.text_input("Guess the original word:")
if st.button("Submit"):
if user_guess.lower() == word:
st.success("Correct!")
else:
st.error("Try again!")
# Emoji Quiz
elif game == "Emoji Quiz":
st.header("😄 Emoji Quiz")
quiz = {
"🐱🐶": "animals",
"🎬🍿": "movie",
"🎓📚": "study",
"🍕🍔": "food"
}
emojis, answer = random.choice(list(quiz.items()))
st.write(f"What category do these emojis represent? {emojis}")
guess = st.text_input("Your answer:")
if st.button("Answer"):
if guess.lower() == answer:
st.success("Correct!")
else:
st.error("Nope! Try again.")
# Score Tracker
elif game == "Score Tracker":
st.header("📊 Score Tracker")
if "score" not in st.session_state:
st.session_state.score = 0
add = st.button("➕ Add Point")
subtract = st.button("➖ Subtract Point")
reset = st.button("🔄 Reset")
if add:
st.session_state.score += 1
elif subtract:
st.session_state.score -= 1
elif reset:
st.session_state.score = 0
st.metric("Current Score", st.session_state.score)
# Dice Roller
elif game == "Dice Roller":
st.header("🎲 Dice Roller")
if st.button("Roll Dice"):
roll = random.randint(1, 6)
st.write(f"🎲 You rolled a {roll}")
# Coin Toss
elif game == "Coin Toss":
st.header("🪙 Coin Toss")
if st.button("Toss Coin"):
toss = random.choice(["Heads", "Tails"])
st.write(f"🪙 It's {toss}!")
# Math Quiz
elif game == "Math Quiz":
st.header("➕ Math Quiz")
a = random.randint(1, 20)
b = random.randint(1, 20)
st.write(f"What is {a} + {b}?")
answer = st.number_input("Your answer:", step=1)
if st.button("Submit Answer"):
if answer == a + b:
st.success("Correct!")
else:
st.error("Wrong answer!")
# Hangman (Very simple)
elif game == "Hangman":
st.header("🪓 Hangman (Lite)")
words = ["apple", "banana", "grape", "orange"]
if "hang_word" not in st.session_state:
st.session_state.hang_word = random.choice(words)
st.session_state.hang_guesses = []
guessed = st.text_input("Guess a letter:").lower()
if st.button("Submit Letter"):
if guessed in st.session_state.hang_word:
st.session_state.hang_guesses.append(guessed)
st.success("Correct!")
else:
st.error("Incorrect.")
display = " ".join([letter if letter in st.session_state.hang_guesses else "_" for letter in st.session_state.hang_word])
st.write("Word:", display)
# Color Guess
elif game == "Color Guess":
st.header("🎨 Color Guess")
colors = ["red", "blue", "green", "yellow", "purple"]
chosen_color = random.choice(colors)
guess = st.selectbox("Pick a color", colors)
if st.button("Guess Color"):
if guess == chosen_color:
st.success("Correct! 🎯")
else:
st.warning(f"Wrong! The color was {chosen_color}")