Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,27 @@
|
|
| 1 |
-
# ------------------ Final Version: Mini Game Arcade (Showcase-Ready) ------------------
|
| 2 |
import streamlit as st
|
| 3 |
import random
|
| 4 |
import time
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
st.set_page_config(page_title="๐ฎ Mini Game Arcade", layout="centered")
|
| 8 |
st.markdown("""
|
| 9 |
<style>
|
| 10 |
-
.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
</style>
|
| 15 |
""", unsafe_allow_html=True)
|
| 16 |
|
| 17 |
-
st.
|
| 18 |
-
st.
|
| 19 |
st.markdown("---")
|
| 20 |
|
| 21 |
# ------------------ Game Selector ------------------
|
|
@@ -24,147 +30,193 @@ games = [
|
|
| 24 |
"Guess the Number",
|
| 25 |
"Word Scramble",
|
| 26 |
"Emoji Quiz",
|
| 27 |
-
"Hangman",
|
| 28 |
"Math Quiz",
|
| 29 |
"Quick Typing Challenge",
|
| 30 |
"Memory Test",
|
| 31 |
-
"Tic Tac Toe"
|
| 32 |
-
"Reaction Timer"
|
| 33 |
]
|
| 34 |
|
| 35 |
-
selected_game = st.selectbox("๐น๏ธ
|
| 36 |
st.markdown("---")
|
| 37 |
|
| 38 |
-
# ------------------
|
| 39 |
-
if "score" not in st.session_state:
|
| 40 |
-
st.session_state.score = 0
|
| 41 |
-
|
| 42 |
-
# ------------------ Game Implementations ------------------
|
| 43 |
-
|
| 44 |
def rock_paper_scissors():
|
| 45 |
-
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 46 |
st.subheader("๐ชจ Rock Paper Scissors")
|
| 47 |
-
|
| 48 |
-
if st.button("Play"):
|
| 49 |
computer = random.choice(["Rock", "Paper", "Scissors"])
|
| 50 |
st.write(f"Computer chose: **{computer}**")
|
| 51 |
-
if
|
| 52 |
st.info("It's a draw!")
|
| 53 |
-
elif (
|
| 54 |
-
(
|
| 55 |
-
(
|
| 56 |
-
st.session_state.score += 1
|
| 57 |
st.success("You win!")
|
| 58 |
else:
|
| 59 |
st.error("You lose!")
|
| 60 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
| 61 |
|
| 62 |
def guess_the_number():
|
| 63 |
-
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 64 |
st.subheader("๐ข Guess the Number")
|
| 65 |
-
if "
|
| 66 |
-
st.session_state.
|
| 67 |
-
st.session_state.attempts_left =
|
| 68 |
-
|
| 69 |
-
guess = st.number_input("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
if st.button("Check"):
|
| 71 |
-
st.session_state.
|
| 72 |
-
if guess == st.session_state.guess_number:
|
| 73 |
st.success("Correct!")
|
| 74 |
-
st.session_state.
|
| 75 |
-
st.session_state.guess_number = random.randint(1, 10)
|
| 76 |
-
st.session_state.attempts_left = 3
|
| 77 |
-
elif st.session_state.attempts_left > 0:
|
| 78 |
-
st.warning(f"Wrong! Attempts left: {st.session_state.attempts_left}")
|
| 79 |
else:
|
| 80 |
-
st.error(
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
def quick_typing():
|
| 86 |
-
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 87 |
st.subheader("โจ๏ธ Quick Typing Challenge")
|
|
|
|
| 88 |
if "typing_word" not in st.session_state:
|
| 89 |
-
st.session_state.typing_word = random.choice(
|
| 90 |
st.session_state.start_time = time.time()
|
| 91 |
|
| 92 |
-
st.info(f"Type this
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
st.error("
|
|
|
|
|
|
|
| 102 |
else:
|
| 103 |
-
st.error(
|
| 104 |
-
st.session_state.typing_word
|
| 105 |
-
st.session_state.start_time = time.time()
|
| 106 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
| 107 |
|
| 108 |
def memory_test():
|
| 109 |
-
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 110 |
st.subheader("๐ง Memory Test")
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
st.session_state.
|
| 114 |
-
st.session_state.
|
| 115 |
-
|
| 116 |
-
if st.session_state.
|
| 117 |
-
st.
|
| 118 |
-
st.write(" ".join(st.session_state.memory_emojis))
|
| 119 |
-
if time.time() - st.session_state.memory_time > 5:
|
| 120 |
-
st.session_state.memory_shown = False
|
| 121 |
else:
|
| 122 |
-
guess = st.text_input("
|
| 123 |
-
if st.button("
|
| 124 |
-
|
| 125 |
-
if guess == correct:
|
| 126 |
st.success("Correct!")
|
| 127 |
-
st.session_state.score += 1
|
| 128 |
else:
|
| 129 |
-
st.error(f"
|
| 130 |
-
st.session_state.
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
st.
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
wait = random.randint(2, 5)
|
| 141 |
-
time.sleep(wait)
|
| 142 |
-
st.session_state.reaction_start = time.time()
|
| 143 |
-
st.success("Click now!")
|
| 144 |
-
elif st.button("Click!"):
|
| 145 |
-
reaction_time = time.time() - st.session_state.reaction_start
|
| 146 |
-
st.success(f"Your reaction time: {reaction_time:.2f} sec")
|
| 147 |
-
st.session_state.score += 1
|
| 148 |
-
del st.session_state.reaction_start
|
| 149 |
-
st.markdown("</div>", unsafe_allow_html=True)
|
| 150 |
-
|
| 151 |
-
# ------------------ Dispatcher ------------------
|
| 152 |
if selected_game == "Rock Paper Scissors":
|
| 153 |
rock_paper_scissors()
|
| 154 |
elif selected_game == "Guess the Number":
|
| 155 |
guess_the_number()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
elif selected_game == "Quick Typing Challenge":
|
| 157 |
quick_typing()
|
| 158 |
elif selected_game == "Memory Test":
|
| 159 |
memory_test()
|
| 160 |
-
elif selected_game == "
|
| 161 |
-
|
| 162 |
-
# Placeholders for rest of games โ you can fill in later as needed.
|
| 163 |
-
|
| 164 |
-
# ------------------ Scoreboard ------------------
|
| 165 |
-
st.markdown("---")
|
| 166 |
-
st.markdown(f"<div class='scoreboard'>๐ Total Score: {st.session_state.score}</div>", unsafe_allow_html=True)
|
| 167 |
|
| 168 |
# ------------------ Footer ------------------
|
| 169 |
st.markdown("---")
|
| 170 |
-
st.markdown("<center
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import random
|
| 3 |
import time
|
| 4 |
+
from datetime import datetime
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="๐ฎ Ultimate Mini Game Arcade", layout="centered")
|
|
|
|
| 7 |
st.markdown("""
|
| 8 |
<style>
|
| 9 |
+
.main {
|
| 10 |
+
background-color: #f4f4f4;
|
| 11 |
+
padding: 1rem;
|
| 12 |
+
border-radius: 20px;
|
| 13 |
+
}
|
| 14 |
+
.game-box {
|
| 15 |
+
background-color: white;
|
| 16 |
+
padding: 1rem;
|
| 17 |
+
border-radius: 15px;
|
| 18 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
| 19 |
+
}
|
| 20 |
</style>
|
| 21 |
""", unsafe_allow_html=True)
|
| 22 |
|
| 23 |
+
st.title("๐ฎ Ultimate Mini Game Arcade")
|
| 24 |
+
st.caption("Play multiple fun games in a beautiful interface โจ")
|
| 25 |
st.markdown("---")
|
| 26 |
|
| 27 |
# ------------------ Game Selector ------------------
|
|
|
|
| 30 |
"Guess the Number",
|
| 31 |
"Word Scramble",
|
| 32 |
"Emoji Quiz",
|
| 33 |
+
"Hangman (Mini)",
|
| 34 |
"Math Quiz",
|
| 35 |
"Quick Typing Challenge",
|
| 36 |
"Memory Test",
|
| 37 |
+
"Tic Tac Toe"
|
|
|
|
| 38 |
]
|
| 39 |
|
| 40 |
+
selected_game = st.selectbox("๐น๏ธ Choose a game to play:", games)
|
| 41 |
st.markdown("---")
|
| 42 |
|
| 43 |
+
# ------------------ Games ------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def rock_paper_scissors():
|
|
|
|
| 45 |
st.subheader("๐ชจ Rock Paper Scissors")
|
| 46 |
+
player = st.radio("Choose your move:", ["Rock", "Paper", "Scissors"], horizontal=True)
|
| 47 |
+
if st.button("Play!"):
|
| 48 |
computer = random.choice(["Rock", "Paper", "Scissors"])
|
| 49 |
st.write(f"Computer chose: **{computer}**")
|
| 50 |
+
if player == computer:
|
| 51 |
st.info("It's a draw!")
|
| 52 |
+
elif (player == "Rock" and computer == "Scissors") or \
|
| 53 |
+
(player == "Paper" and computer == "Rock") or \
|
| 54 |
+
(player == "Scissors" and computer == "Paper"):
|
|
|
|
| 55 |
st.success("You win!")
|
| 56 |
else:
|
| 57 |
st.error("You lose!")
|
|
|
|
| 58 |
|
| 59 |
def guess_the_number():
|
|
|
|
| 60 |
st.subheader("๐ข Guess the Number")
|
| 61 |
+
if "target_number" not in st.session_state:
|
| 62 |
+
st.session_state.target_number = random.randint(1, 20)
|
| 63 |
+
st.session_state.attempts_left = 5
|
| 64 |
+
|
| 65 |
+
guess = st.number_input("Enter a guess (1-20):", min_value=1, max_value=20, step=1)
|
| 66 |
+
col1, col2 = st.columns(2)
|
| 67 |
+
with col1:
|
| 68 |
+
if st.button("Guess"):
|
| 69 |
+
st.session_state.attempts_left -= 1
|
| 70 |
+
if guess == st.session_state.target_number:
|
| 71 |
+
st.success("๐ Correct!")
|
| 72 |
+
del st.session_state.target_number
|
| 73 |
+
elif st.session_state.attempts_left == 0:
|
| 74 |
+
st.error(f"๐ข Out of attempts! The number was {st.session_state.target_number}")
|
| 75 |
+
del st.session_state.target_number
|
| 76 |
+
elif guess < st.session_state.target_number:
|
| 77 |
+
st.warning("Too low!")
|
| 78 |
+
else:
|
| 79 |
+
st.warning("Too high!")
|
| 80 |
+
with col2:
|
| 81 |
+
st.info(f"Attempts left: {st.session_state.attempts_left}")
|
| 82 |
+
|
| 83 |
+
def word_scramble():
|
| 84 |
+
st.subheader("๐ก Word Scramble")
|
| 85 |
+
words = ["streamlit", "developer", "python", "banana"]
|
| 86 |
+
if "scramble_word" not in st.session_state:
|
| 87 |
+
st.session_state.scramble_word = random.choice(words)
|
| 88 |
+
scrambled = ''.join(random.sample(st.session_state.scramble_word, len(st.session_state.scramble_word)))
|
| 89 |
+
st.write(f"Unscramble this: **{scrambled}**")
|
| 90 |
+
answer = st.text_input("Your guess:")
|
| 91 |
if st.button("Check"):
|
| 92 |
+
if answer.lower() == st.session_state.scramble_word:
|
|
|
|
| 93 |
st.success("Correct!")
|
| 94 |
+
del st.session_state.scramble_word
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
else:
|
| 96 |
+
st.error("Try again!")
|
| 97 |
+
|
| 98 |
+
def emoji_quiz():
|
| 99 |
+
st.subheader("๐ Emoji Quiz")
|
| 100 |
+
quiz = {
|
| 101 |
+
"๐๐๐ฅค": "Fast Food",
|
| 102 |
+
"๐ถ๐ฑ": "Pets",
|
| 103 |
+
"๐โ๏ธ": "Travel",
|
| 104 |
+
"โฝ๐": "Sports"
|
| 105 |
+
}
|
| 106 |
+
if "emoji_question" not in st.session_state:
|
| 107 |
+
st.session_state.emoji_question, st.session_state.emoji_answer = random.choice(list(quiz.items()))
|
| 108 |
+
st.write(f"What does this mean? {st.session_state.emoji_question}")
|
| 109 |
+
guess = st.text_input("Your answer:")
|
| 110 |
+
if st.button("Check Answer"):
|
| 111 |
+
if guess.strip().lower() == st.session_state.emoji_answer.lower():
|
| 112 |
+
st.success("Correct!")
|
| 113 |
+
del st.session_state.emoji_question
|
| 114 |
+
del st.session_state.emoji_answer
|
| 115 |
+
else:
|
| 116 |
+
st.error("Nope!")
|
| 117 |
+
|
| 118 |
+
def hangman():
|
| 119 |
+
st.subheader("๐ป Hangman")
|
| 120 |
+
words = ["pen", "sun", "dog", "python"]
|
| 121 |
+
if "hangman_word" not in st.session_state:
|
| 122 |
+
st.session_state.hangman_word = random.choice(words)
|
| 123 |
+
st.session_state.hangman_tries = 5
|
| 124 |
+
|
| 125 |
+
guess = st.text_input("Guess the word:")
|
| 126 |
+
if st.button("Submit"):
|
| 127 |
+
st.session_state.hangman_tries -= 1
|
| 128 |
+
if guess.lower() == st.session_state.hangman_word:
|
| 129 |
+
st.success("Correct!")
|
| 130 |
+
del st.session_state.hangman_word
|
| 131 |
+
elif st.session_state.hangman_tries <= 0:
|
| 132 |
+
st.error(f"Game over! Word was {st.session_state.hangman_word}")
|
| 133 |
+
del st.session_state.hangman_word
|
| 134 |
+
else:
|
| 135 |
+
st.warning(f"Incorrect! Tries left: {st.session_state.hangman_tries}")
|
| 136 |
+
|
| 137 |
+
def math_quiz():
|
| 138 |
+
st.subheader("โ Math Quiz")
|
| 139 |
+
if "a" not in st.session_state:
|
| 140 |
+
st.session_state.a = random.randint(1, 15)
|
| 141 |
+
st.session_state.b = random.randint(1, 15)
|
| 142 |
+
st.write(f"What is {st.session_state.a} + {st.session_state.b}?")
|
| 143 |
+
ans = st.number_input("Your answer:", step=1)
|
| 144 |
+
if st.button("Submit"):
|
| 145 |
+
if ans == st.session_state.a + st.session_state.b:
|
| 146 |
+
st.success("Correct!")
|
| 147 |
+
del st.session_state.a
|
| 148 |
+
del st.session_state.b
|
| 149 |
+
else:
|
| 150 |
+
st.error(f"Wrong! Answer is {st.session_state.a + st.session_state.b}")
|
| 151 |
|
| 152 |
def quick_typing():
|
|
|
|
| 153 |
st.subheader("โจ๏ธ Quick Typing Challenge")
|
| 154 |
+
words = ["keyboard", "streamlit", "python", "arcade"]
|
| 155 |
if "typing_word" not in st.session_state:
|
| 156 |
+
st.session_state.typing_word = random.choice(words)
|
| 157 |
st.session_state.start_time = time.time()
|
| 158 |
|
| 159 |
+
st.info(f"Type this: **{st.session_state.typing_word}**")
|
| 160 |
+
user = st.text_input("Start typing:")
|
| 161 |
+
duration = len(st.session_state.typing_word) * 0.7
|
| 162 |
+
time_passed = time.time() - st.session_state.start_time
|
| 163 |
+
|
| 164 |
+
st.write(f"โณ Time used: {int(time_passed)}s / {int(duration)}s")
|
| 165 |
+
|
| 166 |
+
if st.button("Check"):
|
| 167 |
+
if time_passed > duration:
|
| 168 |
+
st.error("Time exceeded!")
|
| 169 |
+
elif user == st.session_state.typing_word:
|
| 170 |
+
st.success("Perfect!")
|
| 171 |
else:
|
| 172 |
+
st.error("Incorrect!")
|
| 173 |
+
del st.session_state.typing_word
|
|
|
|
|
|
|
| 174 |
|
| 175 |
def memory_test():
|
|
|
|
| 176 |
st.subheader("๐ง Memory Test")
|
| 177 |
+
emojis = random.sample(["๐", "๐", "๐ถ", "๐", "๐", "๐"], 4)
|
| 178 |
+
if "mem_start" not in st.session_state:
|
| 179 |
+
st.session_state.memory_emojis = emojis
|
| 180 |
+
st.session_state.mem_start = datetime.now()
|
| 181 |
+
st.info("You have 5 seconds to memorize these:")
|
| 182 |
+
if (datetime.now() - st.session_state.mem_start).seconds < 5:
|
| 183 |
+
st.code(" ".join(st.session_state.memory_emojis))
|
|
|
|
|
|
|
|
|
|
| 184 |
else:
|
| 185 |
+
guess = st.text_input("Enter one emoji you remember:")
|
| 186 |
+
if st.button("Check"):
|
| 187 |
+
if guess.strip() in st.session_state.memory_emojis:
|
|
|
|
| 188 |
st.success("Correct!")
|
|
|
|
| 189 |
else:
|
| 190 |
+
st.error(f"Oops! Emojis were: {' '.join(st.session_state.memory_emojis)}")
|
| 191 |
+
del st.session_state.mem_start
|
| 192 |
+
|
| 193 |
+
# Placeholder for Tic Tac Toe โ add if desired
|
| 194 |
+
|
| 195 |
+
def tic_tac_toe():
|
| 196 |
+
st.subheader("โ Tic Tac Toe")
|
| 197 |
+
st.info("Coming soon or under construction ๐๏ธ")
|
| 198 |
+
|
| 199 |
+
# ------------------ Game Dispatcher ------------------
|
| 200 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
if selected_game == "Rock Paper Scissors":
|
| 202 |
rock_paper_scissors()
|
| 203 |
elif selected_game == "Guess the Number":
|
| 204 |
guess_the_number()
|
| 205 |
+
elif selected_game == "Word Scramble":
|
| 206 |
+
word_scramble()
|
| 207 |
+
elif selected_game == "Emoji Quiz":
|
| 208 |
+
emoji_quiz()
|
| 209 |
+
elif selected_game == "Hangman (Mini)":
|
| 210 |
+
hangman()
|
| 211 |
+
elif selected_game == "Math Quiz":
|
| 212 |
+
math_quiz()
|
| 213 |
elif selected_game == "Quick Typing Challenge":
|
| 214 |
quick_typing()
|
| 215 |
elif selected_game == "Memory Test":
|
| 216 |
memory_test()
|
| 217 |
+
elif selected_game == "Tic Tac Toe":
|
| 218 |
+
tic_tac_toe()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
| 220 |
# ------------------ Footer ------------------
|
| 221 |
st.markdown("---")
|
| 222 |
+
st.markdown("<center>๐ Made with โค๏ธ to impress professors and professionals on LinkedIn!</center>", unsafe_allow_html=True)
|