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