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