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