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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import random
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
# ------------------ Page Setup ------------------
|
| 6 |
+
st.set_page_config(page_title="๐ฎ Mini Game Arcade", layout="centered")
|
| 7 |
+
st.title("๐ฎ Mini Game Arcade")
|
| 8 |
+
st.markdown("Choose a game from the list and have fun!")
|
| 9 |
+
|
| 10 |
+
# ------------------ Game Selector ------------------
|
| 11 |
+
games = [
|
| 12 |
+
"Rock Paper Scissors",
|
| 13 |
+
"Guess the Number",
|
| 14 |
+
"Word Scramble",
|
| 15 |
+
"Emoji Quiz",
|
| 16 |
+
"Coin Toss",
|
| 17 |
+
"Dice Roll",
|
| 18 |
+
"Hangman (Mini)",
|
| 19 |
+
"Math Quiz",
|
| 20 |
+
"Quick Typing Challenge",
|
| 21 |
+
"Memory Test"
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
selected_game = st.selectbox("๐น๏ธ Pick a game to play", games)
|
| 25 |
+
|
| 26 |
+
# ------------------ Game Functions ------------------
|
| 27 |
+
|
| 28 |
+
def rock_paper_scissors():
|
| 29 |
+
st.subheader("๐ชจ Rock Paper Scissors")
|
| 30 |
+
user = st.radio("Choose your move:", ["Rock", "Paper", "Scissors"])
|
| 31 |
+
if st.button("Play"):
|
| 32 |
+
computer = random.choice(["Rock", "Paper", "Scissors"])
|
| 33 |
+
st.write(f"Computer chose **{computer}**")
|
| 34 |
+
if user == computer:
|
| 35 |
+
st.success("It's a draw!")
|
| 36 |
+
elif (user == "Rock" and computer == "Scissors") or \
|
| 37 |
+
(user == "Paper" and computer == "Rock") or \
|
| 38 |
+
(user == "Scissors" and computer == "Paper"):
|
| 39 |
+
st.success("You win!")
|
| 40 |
+
else:
|
| 41 |
+
st.error("You lose!")
|
| 42 |
+
|
| 43 |
+
def guess_the_number():
|
| 44 |
+
st.subheader("๐ข Guess the Number (1-10)")
|
| 45 |
+
number = random.randint(1, 10)
|
| 46 |
+
guess = st.number_input("Your guess:", 1, 10, step=1)
|
| 47 |
+
if st.button("Check"):
|
| 48 |
+
if guess == number:
|
| 49 |
+
st.success("Correct! ๐")
|
| 50 |
+
else:
|
| 51 |
+
st.error(f"Wrong! It was {number}")
|
| 52 |
+
|
| 53 |
+
def word_scramble():
|
| 54 |
+
st.subheader("๐ค Word Scramble")
|
| 55 |
+
words = ["python", "arcade", "streamlit", "banana", "gamer"]
|
| 56 |
+
word = random.choice(words)
|
| 57 |
+
scrambled = "".join(random.sample(word, len(word)))
|
| 58 |
+
st.write(f"Unscramble this word: **{scrambled}**")
|
| 59 |
+
guess = st.text_input("Your guess:")
|
| 60 |
+
if st.button("Submit"):
|
| 61 |
+
if guess.lower() == word:
|
| 62 |
+
st.success("Correct!")
|
| 63 |
+
else:
|
| 64 |
+
st.error(f"Nope! The word was **{word}**")
|
| 65 |
+
|
| 66 |
+
def emoji_quiz():
|
| 67 |
+
st.subheader("๐ Emoji Quiz")
|
| 68 |
+
quiz = {
|
| 69 |
+
"๐๐๐": "Fast Food",
|
| 70 |
+
"๐๐จ": "Speed",
|
| 71 |
+
"๐ฑ๐ถ": "Pets",
|
| 72 |
+
"โ๏ธ๐": "Travel"
|
| 73 |
+
}
|
| 74 |
+
emojis, answer = random.choice(list(quiz.items()))
|
| 75 |
+
st.write(f"What do these emojis mean? {emojis}")
|
| 76 |
+
guess = st.text_input("Your answer:")
|
| 77 |
+
if st.button("Check Answer"):
|
| 78 |
+
if guess.lower() == answer.lower():
|
| 79 |
+
st.success("Correct!")
|
| 80 |
+
else:
|
| 81 |
+
st.error(f"The correct answer was **{answer}**")
|
| 82 |
+
|
| 83 |
+
def coin_toss():
|
| 84 |
+
st.subheader("๐ช Coin Toss")
|
| 85 |
+
if st.button("Toss Coin"):
|
| 86 |
+
result = random.choice(["Heads", "Tails"])
|
| 87 |
+
st.write(f"๐ช It's **{result}**!")
|
| 88 |
+
|
| 89 |
+
def dice_roll():
|
| 90 |
+
st.subheader("๐ฒ Dice Roll")
|
| 91 |
+
if st.button("Roll Dice"):
|
| 92 |
+
result = random.randint(1, 6)
|
| 93 |
+
st.write(f"๐ฒ You rolled a **{result}**!")
|
| 94 |
+
|
| 95 |
+
def hangman_mini():
|
| 96 |
+
st.subheader("๐ป Hangman (Mini)")
|
| 97 |
+
words = ["sun", "pen", "dog", "cup", "cat"]
|
| 98 |
+
word = random.choice(words)
|
| 99 |
+
st.write(f"The word has {len(word)} letters.")
|
| 100 |
+
guess = st.text_input("Guess the word:")
|
| 101 |
+
if st.button("Reveal"):
|
| 102 |
+
if guess.lower() == word:
|
| 103 |
+
st.success("Correct!")
|
| 104 |
+
else:
|
| 105 |
+
st.error(f"The word was **{word}**")
|
| 106 |
+
|
| 107 |
+
def math_quiz():
|
| 108 |
+
st.subheader("โ Math Quiz")
|
| 109 |
+
a = random.randint(1, 20)
|
| 110 |
+
b = random.randint(1, 20)
|
| 111 |
+
st.write(f"What is {a} + {b}?")
|
| 112 |
+
answer = st.number_input("Your answer:", step=1)
|
| 113 |
+
if st.button("Submit"):
|
| 114 |
+
if answer == a + b:
|
| 115 |
+
st.success("Correct!")
|
| 116 |
+
else:
|
| 117 |
+
st.error(f"Wrong! The answer is **{a + b}**")
|
| 118 |
+
|
| 119 |
+
def quick_typing():
|
| 120 |
+
st.subheader("โจ๏ธ Quick Typing Challenge")
|
| 121 |
+
word = random.choice(["elephant", "keyboard", "arcade", "stream", "python"])
|
| 122 |
+
st.write(f"Type this word exactly: **{word}**")
|
| 123 |
+
user_input = st.text_input("Start typing:")
|
| 124 |
+
if st.button("Submit"):
|
| 125 |
+
if user_input == word:
|
| 126 |
+
st.success("Well done!")
|
| 127 |
+
else:
|
| 128 |
+
st.error("Mismatch! Try again.")
|
| 129 |
+
|
| 130 |
+
def memory_test():
|
| 131 |
+
st.subheader("๐ง Memory Test")
|
| 132 |
+
nums = random.sample(range(1, 100), 5)
|
| 133 |
+
st.write("Remember these numbers:")
|
| 134 |
+
st.code(nums)
|
| 135 |
+
time.sleep(3)
|
| 136 |
+
st.write("Now enter any one number you remember:")
|
| 137 |
+
guess = st.number_input("Enter a number:", step=1)
|
| 138 |
+
if st.button("Check"):
|
| 139 |
+
if guess in nums:
|
| 140 |
+
st.success("Correct!")
|
| 141 |
+
else:
|
| 142 |
+
st.error(f"Oops! Numbers were: {nums}")
|
| 143 |
+
|
| 144 |
+
# ------------------ Game Dispatcher ------------------
|
| 145 |
+
|
| 146 |
+
if selected_game == "Rock Paper Scissors":
|
| 147 |
+
rock_paper_scissors()
|
| 148 |
+
elif selected_game == "Guess the Number":
|
| 149 |
+
guess_the_number()
|
| 150 |
+
elif selected_game == "Word Scramble":
|
| 151 |
+
word_scramble()
|
| 152 |
+
elif selected_game == "Emoji Quiz":
|
| 153 |
+
emoji_quiz()
|
| 154 |
+
elif selected_game == "Coin Toss":
|
| 155 |
+
coin_toss()
|
| 156 |
+
elif selected_game == "Dice Roll":
|
| 157 |
+
dice_roll()
|
| 158 |
+
elif selected_game == "Hangman (Mini)":
|
| 159 |
+
hangman_mini()
|
| 160 |
+
elif selected_game == "Math Quiz":
|
| 161 |
+
math_quiz()
|
| 162 |
+
elif selected_game == "Quick Typing Challenge":
|
| 163 |
+
quick_typing()
|
| 164 |
+
elif selected_game == "Memory Test":
|
| 165 |
+
memory_test()
|
| 166 |
+
|
| 167 |
+
# ------------------ Footer ------------------
|
| 168 |
+
st.markdown("---")
|
| 169 |
+
st.markdown("Made with โค๏ธ for fun and learning.")
|