Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ 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 {
|
|
@@ -24,7 +25,6 @@ st.title("๐ฎ Ultimate Mini Game Arcade")
|
|
| 24 |
st.caption("Play multiple fun games in a beautiful interface โจ")
|
| 25 |
st.markdown("---")
|
| 26 |
|
| 27 |
-
# ------------------ Game Selector ------------------
|
| 28 |
games = [
|
| 29 |
"Rock Paper Scissors",
|
| 30 |
"Guess the Number",
|
|
@@ -33,14 +33,13 @@ games = [
|
|
| 33 |
"Hangman (Mini)",
|
| 34 |
"Math Quiz",
|
| 35 |
"Quick Typing Challenge",
|
| 36 |
-
"
|
| 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)
|
|
@@ -85,15 +84,24 @@ def 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 |
-
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
if answer.lower() == st.session_state.scramble_word:
|
| 93 |
st.success("Correct!")
|
| 94 |
del st.session_state.scramble_word
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
else:
|
| 96 |
-
st.
|
|
|
|
| 97 |
|
| 98 |
def emoji_quiz():
|
| 99 |
st.subheader("๐ Emoji Quiz")
|
|
@@ -122,17 +130,21 @@ def hangman():
|
|
| 122 |
st.session_state.hangman_word = random.choice(words)
|
| 123 |
st.session_state.hangman_tries = 5
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
|
|
|
| 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(
|
|
|
|
| 136 |
|
| 137 |
def math_quiz():
|
| 138 |
st.subheader("โ Math Quiz")
|
|
@@ -161,7 +173,10 @@ def quick_typing():
|
|
| 161 |
duration = len(st.session_state.typing_word) * 0.7
|
| 162 |
time_passed = time.time() - st.session_state.start_time
|
| 163 |
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
if st.button("Check"):
|
| 167 |
if time_passed > duration:
|
|
@@ -172,32 +187,43 @@ def quick_typing():
|
|
| 172 |
st.error("Incorrect!")
|
| 173 |
del st.session_state.typing_word
|
| 174 |
|
| 175 |
-
def
|
| 176 |
-
st.subheader("
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
st.session_state.
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
guess
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 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 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
if selected_game == "Rock Paper Scissors":
|
| 202 |
rock_paper_scissors()
|
| 203 |
elif selected_game == "Guess the Number":
|
|
@@ -212,11 +238,10 @@ elif selected_game == "Math Quiz":
|
|
| 212 |
math_quiz()
|
| 213 |
elif selected_game == "Quick Typing Challenge":
|
| 214 |
quick_typing()
|
| 215 |
-
elif selected_game == "
|
| 216 |
-
|
| 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)
|
|
|
|
| 4 |
from datetime import datetime
|
| 5 |
|
| 6 |
st.set_page_config(page_title="๐ฎ Ultimate Mini Game Arcade", layout="centered")
|
| 7 |
+
|
| 8 |
st.markdown("""
|
| 9 |
<style>
|
| 10 |
.main {
|
|
|
|
| 25 |
st.caption("Play multiple fun games in a beautiful interface โจ")
|
| 26 |
st.markdown("---")
|
| 27 |
|
|
|
|
| 28 |
games = [
|
| 29 |
"Rock Paper Scissors",
|
| 30 |
"Guess the Number",
|
|
|
|
| 33 |
"Hangman (Mini)",
|
| 34 |
"Math Quiz",
|
| 35 |
"Quick Typing Challenge",
|
| 36 |
+
"Color Match",
|
| 37 |
"Tic Tac Toe"
|
| 38 |
]
|
| 39 |
|
| 40 |
selected_game = st.selectbox("๐น๏ธ Choose a game to play:", games)
|
| 41 |
st.markdown("---")
|
| 42 |
|
|
|
|
| 43 |
def rock_paper_scissors():
|
| 44 |
st.subheader("๐ชจ Rock Paper Scissors")
|
| 45 |
player = st.radio("Choose your move:", ["Rock", "Paper", "Scissors"], horizontal=True)
|
|
|
|
| 84 |
words = ["streamlit", "developer", "python", "banana"]
|
| 85 |
if "scramble_word" not in st.session_state:
|
| 86 |
st.session_state.scramble_word = random.choice(words)
|
| 87 |
+
st.session_state.scramble_attempts = 3
|
| 88 |
scrambled = ''.join(random.sample(st.session_state.scramble_word, len(st.session_state.scramble_word)))
|
| 89 |
st.write(f"Unscramble this: **{scrambled}**")
|
| 90 |
+
col1, col2 = st.columns(2)
|
| 91 |
+
answer = col1.text_input("Your guess:")
|
| 92 |
+
if col1.button("Check"):
|
| 93 |
+
st.session_state.scramble_attempts -= 1
|
| 94 |
if answer.lower() == st.session_state.scramble_word:
|
| 95 |
st.success("Correct!")
|
| 96 |
del st.session_state.scramble_word
|
| 97 |
+
del st.session_state.scramble_attempts
|
| 98 |
+
elif st.session_state.scramble_attempts == 0:
|
| 99 |
+
st.error(f"Out of attempts! The word was {st.session_state.scramble_word}")
|
| 100 |
+
del st.session_state.scramble_word
|
| 101 |
+
del st.session_state.scramble_attempts
|
| 102 |
else:
|
| 103 |
+
st.warning("Try again!")
|
| 104 |
+
col2.info(f"Attempts left: {st.session_state.scramble_attempts}")
|
| 105 |
|
| 106 |
def emoji_quiz():
|
| 107 |
st.subheader("๐ Emoji Quiz")
|
|
|
|
| 130 |
st.session_state.hangman_word = random.choice(words)
|
| 131 |
st.session_state.hangman_tries = 5
|
| 132 |
|
| 133 |
+
col1, col2 = st.columns(2)
|
| 134 |
+
guess = col1.text_input("Guess the word:")
|
| 135 |
+
if col1.button("Submit"):
|
| 136 |
st.session_state.hangman_tries -= 1
|
| 137 |
if guess.lower() == st.session_state.hangman_word:
|
| 138 |
st.success("Correct!")
|
| 139 |
del st.session_state.hangman_word
|
| 140 |
+
del st.session_state.hangman_tries
|
| 141 |
elif st.session_state.hangman_tries <= 0:
|
| 142 |
st.error(f"Game over! Word was {st.session_state.hangman_word}")
|
| 143 |
del st.session_state.hangman_word
|
| 144 |
+
del st.session_state.hangman_tries
|
| 145 |
else:
|
| 146 |
+
st.warning("Try again!")
|
| 147 |
+
col2.info(f"Tries left: {st.session_state.hangman_tries}")
|
| 148 |
|
| 149 |
def math_quiz():
|
| 150 |
st.subheader("โ Math Quiz")
|
|
|
|
| 173 |
duration = len(st.session_state.typing_word) * 0.7
|
| 174 |
time_passed = time.time() - st.session_state.start_time
|
| 175 |
|
| 176 |
+
if time_passed > duration:
|
| 177 |
+
st.markdown(f"โฑ๏ธ **Time used:** :red[{int(time_passed)}s] / {int(duration)}s")
|
| 178 |
+
else:
|
| 179 |
+
st.markdown(f"โฑ๏ธ **Time used:** :green[{int(time_passed)}s] / {int(duration)}s")
|
| 180 |
|
| 181 |
if st.button("Check"):
|
| 182 |
if time_passed > duration:
|
|
|
|
| 187 |
st.error("Incorrect!")
|
| 188 |
del st.session_state.typing_word
|
| 189 |
|
| 190 |
+
def color_match():
|
| 191 |
+
st.subheader("๐จ Color Match Game")
|
| 192 |
+
colors = ["Red", "Green", "Blue", "Yellow"]
|
| 193 |
+
color_word = random.choice(colors)
|
| 194 |
+
if "color_target" not in st.session_state:
|
| 195 |
+
st.session_state.color_target = color_word
|
| 196 |
+
|
| 197 |
+
st.markdown(f"**Word says:** `{st.session_state.color_target}`")
|
| 198 |
+
guess = st.radio("Which color is it?", colors, horizontal=True)
|
| 199 |
+
if st.button("Match"):
|
| 200 |
+
if guess == st.session_state.color_target:
|
| 201 |
+
st.success("Matched!")
|
| 202 |
+
else:
|
| 203 |
+
st.error("Nope, try again!")
|
| 204 |
+
del st.session_state.color_target
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
def tic_tac_toe():
|
| 207 |
st.subheader("โ Tic Tac Toe")
|
| 208 |
+
if "board" not in st.session_state:
|
| 209 |
+
st.session_state.board = [""] * 9
|
| 210 |
+
st.session_state.turn = "X"
|
| 211 |
+
cols = st.columns(3)
|
| 212 |
+
for i in range(3):
|
| 213 |
+
for j in range(3):
|
| 214 |
+
idx = 3 * i + j
|
| 215 |
+
if cols[j].button(st.session_state.board[idx] or "-", key=idx):
|
| 216 |
+
if st.session_state.board[idx] == "":
|
| 217 |
+
st.session_state.board[idx] = st.session_state.turn
|
| 218 |
+
st.session_state.turn = "O" if st.session_state.turn == "X" else "X"
|
| 219 |
+
wins = [(0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)]
|
| 220 |
+
for a,b,c in wins:
|
| 221 |
+
if st.session_state.board[a] != "" and st.session_state.board[a] == st.session_state.board[b] == st.session_state.board[c]:
|
| 222 |
+
st.success(f"๐ {st.session_state.board[a]} wins!")
|
| 223 |
+
st.session_state.board = [""] * 9
|
| 224 |
+
break
|
| 225 |
+
|
| 226 |
+
# Game Dispatcher
|
| 227 |
if selected_game == "Rock Paper Scissors":
|
| 228 |
rock_paper_scissors()
|
| 229 |
elif selected_game == "Guess the Number":
|
|
|
|
| 238 |
math_quiz()
|
| 239 |
elif selected_game == "Quick Typing Challenge":
|
| 240 |
quick_typing()
|
| 241 |
+
elif selected_game == "Color Match":
|
| 242 |
+
color_match()
|
| 243 |
elif selected_game == "Tic Tac Toe":
|
| 244 |
tic_tac_toe()
|
| 245 |
|
|
|
|
| 246 |
st.markdown("---")
|
| 247 |
st.markdown("<center>๐ Made with โค๏ธ to impress professors and professionals on LinkedIn!</center>", unsafe_allow_html=True)
|