Mahrukhh commited on
Commit
1bb80aa
ยท
verified ยท
1 Parent(s): ff4a027

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -36
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
- "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)
@@ -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
- 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")
@@ -122,17 +130,21 @@ def hangman():
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")
@@ -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
- st.write(f"โณ Time used: {int(time_passed)}s / {int(duration)}s")
 
 
 
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 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":
@@ -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 == "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)
 
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)