Mahrukhh commited on
Commit
eda6548
ยท
verified ยท
1 Parent(s): dcc223c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -135
app.py CHANGED
@@ -1,67 +1,45 @@
1
  import streamlit as st
 
2
  import random
 
3
  import time
4
  from datetime import datetime
5
- from streamlit_lottie import st_lottie
6
- import requests
7
 
8
  st.set_page_config(page_title="๐ŸŽฎ Ultimate Mini Game Arcade", layout="centered")
9
 
10
- # ------------------ Styling ------------------
11
- st.markdown("""
12
- <style>
13
- .main {
14
- background-color: #f4f4f4;
15
- padding: 1rem;
16
- border-radius: 20px;
17
- }
18
- .game-box {
19
- background-color: white;
20
- padding: 1rem;
21
- border-radius: 15px;
22
- box-shadow: 0 0 10px rgba(0,0,0,0.1);
23
- }
24
- </style>
25
- """, unsafe_allow_html=True)
26
-
27
- # ------------------ Animation Loader ------------------
28
- def load_lottie(url):
29
  r = requests.get(url)
30
- if r.status_code != 200:
31
- return None
32
- return r.json()
33
 
34
- # Animations
35
- lottie_gamepad = load_lottie("https://lottie.host/0705a3e4-e9a5-4f3d-aeb9-3adcf013b0a0/Kw83Qw4g0o.json")
36
- lottie_win = load_lottie("https://lottie.host/bb0608f5-2e3f-4f34-8807-61f35f01f8d1/zH2zKuMIoH.json")
37
- lottie_lose = load_lottie("https://lottie.host/94f0aa61-daa8-4ff3-8716-bdbb9cf1010c/hEzI1FfMFA.json")
38
- lottie_typing = load_lottie("https://lottie.host/0e342720-2d97-4ab3-9b91-4ccdc2df5db5/gZ5I7lLWB0.json")
39
 
40
- st_lottie(lottie_gamepad, height=200)
41
  st.title("๐ŸŽฎ Ultimate Mini Game Arcade")
42
- st.caption("Play multiple fun games in a beautiful interface โœจ")
43
  st.markdown("---")
44
 
45
- # ------------------ Game Selector ------------------
46
  games = [
47
  "Rock Paper Scissors",
48
  "Guess the Number",
49
  "Word Scramble",
50
  "Emoji Quiz",
51
- "Hangman (Mini)",
52
  "Math Quiz",
53
- "Quick Typing Challenge",
54
- "Color Match",
55
  "Tic Tac Toe"
56
  ]
57
-
58
- selected_game = st.selectbox("๐Ÿ•น๏ธ Choose a game to play:", games)
59
  st.markdown("---")
60
 
61
- # ------------------ Games ------------------
62
  def rock_paper_scissors():
63
  st.subheader("๐Ÿชจ Rock Paper Scissors")
64
- player = st.radio("Choose your move:", ["Rock", "Paper", "Scissors"], horizontal=True)
65
  if st.button("Play!"):
66
  computer = random.choice(["Rock", "Paper", "Scissors"])
67
  st.write(f"Computer chose: **{computer}**")
@@ -71,10 +49,8 @@ def rock_paper_scissors():
71
  (player == "Paper" and computer == "Rock") or \
72
  (player == "Scissors" and computer == "Paper"):
73
  st.success("You win!")
74
- st_lottie(lottie_win, height=150)
75
  else:
76
  st.error("You lose!")
77
- st_lottie(lottie_lose, height=150)
78
 
79
  def guess_the_number():
80
  st.subheader("๐Ÿ”ข Guess the Number")
@@ -89,41 +65,41 @@ def guess_the_number():
89
  st.session_state.attempts_left -= 1
90
  if guess == st.session_state.target_number:
91
  st.success("๐ŸŽ‰ Correct!")
92
- st_lottie(lottie_win, height=150)
93
  del st.session_state.target_number
94
  elif st.session_state.attempts_left == 0:
95
  st.error(f"๐Ÿ˜ข Out of attempts! The number was {st.session_state.target_number}")
96
- st_lottie(lottie_lose, height=150)
97
  del st.session_state.target_number
98
  elif guess < st.session_state.target_number:
99
  st.warning("Too low!")
100
  else:
101
  st.warning("Too high!")
102
  with col2:
103
- st.info(f"Attempts left: {st.session_state.attempts_left}")
104
 
105
  def word_scramble():
106
  st.subheader("๐Ÿ”ก Word Scramble")
107
  words = ["streamlit", "developer", "python", "banana"]
108
  if "scramble_word" not in st.session_state:
109
  st.session_state.scramble_word = random.choice(words)
110
- st.session_state.scramble_tries = 3
111
-
112
  scrambled = ''.join(random.sample(st.session_state.scramble_word, len(st.session_state.scramble_word)))
113
  st.write(f"Unscramble this: **{scrambled}**")
 
114
  col1, col2 = st.columns(2)
115
- answer = col1.text_input("Your guess:")
116
- col2.info(f"Chances left: {st.session_state.scramble_tries}")
117
- if st.button("Check"):
118
- st.session_state.scramble_tries -= 1
119
- if answer.lower() == st.session_state.scramble_word:
120
- st.success("Correct!")
121
- st_lottie(lottie_win, height=150)
122
- del st.session_state.scramble_word
123
- elif st.session_state.scramble_tries <= 0:
124
- st.error(f"Out of chances! Word was: {st.session_state.scramble_word}")
125
- st_lottie(lottie_lose, height=150)
126
- del st.session_state.scramble_word
 
 
127
 
128
  def emoji_quiz():
129
  st.subheader("๐Ÿ˜ Emoji Quiz")
@@ -140,7 +116,6 @@ def emoji_quiz():
140
  if st.button("Check Answer"):
141
  if guess.strip().lower() == st.session_state.emoji_answer.lower():
142
  st.success("Correct!")
143
- st_lottie(lottie_win, height=150)
144
  del st.session_state.emoji_question
145
  del st.session_state.emoji_answer
146
  else:
@@ -152,19 +127,21 @@ def hangman():
152
  if "hangman_word" not in st.session_state:
153
  st.session_state.hangman_word = random.choice(words)
154
  st.session_state.hangman_tries = 5
 
155
  col1, col2 = st.columns(2)
156
- guess = col1.text_input("Guess the word:")
157
- col2.info(f"Tries left: {st.session_state.hangman_tries}")
158
- if st.button("Submit"):
159
- st.session_state.hangman_tries -= 1
160
- if guess.lower() == st.session_state.hangman_word:
161
- st.success("Correct!")
162
- st_lottie(lottie_win, height=150)
163
- del st.session_state.hangman_word
164
- elif st.session_state.hangman_tries <= 0:
165
- st.error(f"Game over! Word was {st.session_state.hangman_word}")
166
- st_lottie(lottie_lose, height=150)
167
- del st.session_state.hangman_word
 
168
 
169
  def math_quiz():
170
  st.subheader("โž• Math Quiz")
@@ -176,88 +153,54 @@ def math_quiz():
176
  if st.button("Submit"):
177
  if ans == st.session_state.a + st.session_state.b:
178
  st.success("Correct!")
179
- st_lottie(lottie_win, height=150)
180
- del st.session_state.a
181
- del st.session_state.b
182
  else:
183
  st.error(f"Wrong! Answer is {st.session_state.a + st.session_state.b}")
184
- st_lottie(lottie_lose, height=150)
 
185
 
186
  def quick_typing():
187
- st.subheader("โŒจ๏ธ Quick Typing Challenge")
188
  words = ["keyboard", "streamlit", "python", "arcade"]
189
  if "typing_word" not in st.session_state:
190
  st.session_state.typing_word = random.choice(words)
191
  st.session_state.start_time = time.time()
192
-
193
- st_lottie(lottie_typing, height=150)
194
  st.info(f"Type this: **{st.session_state.typing_word}**")
195
  user = st.text_input("Start typing:")
196
- duration = len(st.session_state.typing_word) * 0.7
197
  time_passed = time.time() - st.session_state.start_time
198
-
199
  st.write(f"โณ Time used: {int(time_passed)}s / {int(duration)}s")
200
-
201
  if st.button("Check"):
202
  if time_passed > duration:
203
- st.error("Time exceeded!")
204
- st_lottie(lottie_lose, height=150)
205
  elif user == st.session_state.typing_word:
206
  st.success("Perfect!")
207
- st_lottie(lottie_win, height=150)
208
  else:
209
  st.error("Incorrect!")
210
  del st.session_state.typing_word
211
 
212
- def color_match():
213
- st.subheader("๐ŸŽจ Color Match")
214
- colors = ["red", "blue", "green", "yellow", "purple"]
215
- if "color_word" not in st.session_state:
216
- st.session_state.color_word = random.choice(colors)
217
- displayed = st.color_picker("Pick the correct color:", "#000000")
218
- if st.button("Check Color"):
219
- st.write(f"Target was: **{st.session_state.color_word}**")
220
- if st.session_state.color_word in displayed:
221
- st.success("Great eye!")
222
- st_lottie(lottie_win, height=150)
223
- else:
224
- st.error("Try again!")
225
- st_lottie(lottie_lose, height=150)
226
- del st.session_state.color_word
 
 
227
 
228
  def tic_tac_toe():
229
  st.subheader("โŒ Tic Tac Toe")
230
- if "board" not in st.session_state:
231
- st.session_state.board = [""] * 9
232
- st.session_state.turn = "X"
233
- st.session_state.winner = None
234
-
235
- def check_winner(b):
236
- 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)]
237
- for i,j,k in wins:
238
- if b[i] == b[j] == b[k] and b[i] != "":
239
- return b[i]
240
- return None
241
-
242
- for i in range(3):
243
- cols = st.columns(3)
244
- for j in range(3):
245
- idx = i * 3 + j
246
- if cols[j].button(st.session_state.board[idx] or " ", key=idx) and not st.session_state.board[idx] and not st.session_state.winner:
247
- st.session_state.board[idx] = st.session_state.turn
248
- st.session_state.winner = check_winner(st.session_state.board)
249
- if not st.session_state.winner:
250
- st.session_state.turn = "O" if st.session_state.turn == "X" else "X"
251
-
252
- if st.session_state.winner:
253
- st.success(f"Player {st.session_state.winner} wins!")
254
- st_lottie(lottie_win, height=150)
255
- st.session_state.board = [""] * 9
256
- st.session_state.turn = "X"
257
- st.session_state.winner = None
258
-
259
- # ------------------ Game Dispatcher ------------------
260
 
 
261
  if selected_game == "Rock Paper Scissors":
262
  rock_paper_scissors()
263
  elif selected_game == "Guess the Number":
@@ -266,17 +209,16 @@ elif selected_game == "Word Scramble":
266
  word_scramble()
267
  elif selected_game == "Emoji Quiz":
268
  emoji_quiz()
269
- elif selected_game == "Hangman (Mini)":
270
  hangman()
271
  elif selected_game == "Math Quiz":
272
  math_quiz()
273
- elif selected_game == "Quick Typing Challenge":
274
  quick_typing()
275
- elif selected_game == "Color Match":
276
- color_match()
277
  elif selected_game == "Tic Tac Toe":
278
  tic_tac_toe()
279
 
280
- # ------------------ Footer ------------------
281
  st.markdown("---")
282
- st.markdown("<center>๐Ÿš€ Made with โค๏ธ to impress professors and professionals on LinkedIn!</center>", unsafe_allow_html=True)
 
1
  import streamlit as st
2
+ from streamlit_lottie import st_lottie
3
  import random
4
+ import requests
5
  import time
6
  from datetime import datetime
 
 
7
 
8
  st.set_page_config(page_title="๐ŸŽฎ Ultimate Mini Game Arcade", layout="centered")
9
 
10
+ # Load Lottie animation
11
+ def load_lottieurl(url):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  r = requests.get(url)
13
+ if r.status_code == 200:
14
+ return r.json()
15
+ return None
16
 
17
+ lottie_gamepad = load_lottieurl("https://lottie.host/02f43b1d-15c7-4055-a02d-bbfb25d9b5f6/KUzEMZuOE4.json")
18
+ if lottie_gamepad:
19
+ st_lottie(lottie_gamepad, height=200)
 
 
20
 
 
21
  st.title("๐ŸŽฎ Ultimate Mini Game Arcade")
22
+ st.caption("Fun games in a beautiful interface โœจ")
23
  st.markdown("---")
24
 
 
25
  games = [
26
  "Rock Paper Scissors",
27
  "Guess the Number",
28
  "Word Scramble",
29
  "Emoji Quiz",
30
+ "Hangman",
31
  "Math Quiz",
32
+ "Quick Typing",
33
+ "Emoji Memory Match",
34
  "Tic Tac Toe"
35
  ]
36
+ selected_game = st.selectbox("๐Ÿ•น๏ธ Choose a game:", games)
 
37
  st.markdown("---")
38
 
39
+ # Games
40
  def rock_paper_scissors():
41
  st.subheader("๐Ÿชจ Rock Paper Scissors")
42
+ player = st.radio("Your move:", ["Rock", "Paper", "Scissors"], horizontal=True)
43
  if st.button("Play!"):
44
  computer = random.choice(["Rock", "Paper", "Scissors"])
45
  st.write(f"Computer chose: **{computer}**")
 
49
  (player == "Paper" and computer == "Rock") or \
50
  (player == "Scissors" and computer == "Paper"):
51
  st.success("You win!")
 
52
  else:
53
  st.error("You lose!")
 
54
 
55
  def guess_the_number():
56
  st.subheader("๐Ÿ”ข Guess the Number")
 
65
  st.session_state.attempts_left -= 1
66
  if guess == st.session_state.target_number:
67
  st.success("๐ŸŽ‰ Correct!")
 
68
  del st.session_state.target_number
69
  elif st.session_state.attempts_left == 0:
70
  st.error(f"๐Ÿ˜ข Out of attempts! The number was {st.session_state.target_number}")
 
71
  del st.session_state.target_number
72
  elif guess < st.session_state.target_number:
73
  st.warning("Too low!")
74
  else:
75
  st.warning("Too high!")
76
  with col2:
77
+ st.info(f"๐ŸŽฏ Attempts left: {st.session_state.attempts_left}")
78
 
79
  def word_scramble():
80
  st.subheader("๐Ÿ”ก Word Scramble")
81
  words = ["streamlit", "developer", "python", "banana"]
82
  if "scramble_word" not in st.session_state:
83
  st.session_state.scramble_word = random.choice(words)
84
+ st.session_state.scramble_attempts = 3
 
85
  scrambled = ''.join(random.sample(st.session_state.scramble_word, len(st.session_state.scramble_word)))
86
  st.write(f"Unscramble this: **{scrambled}**")
87
+ answer = st.text_input("Your guess:")
88
  col1, col2 = st.columns(2)
89
+ with col1:
90
+ if st.button("Check"):
91
+ if answer.lower() == st.session_state.scramble_word:
92
+ st.success("Correct!")
93
+ del st.session_state.scramble_word
94
+ else:
95
+ st.session_state.scramble_attempts -= 1
96
+ if st.session_state.scramble_attempts <= 0:
97
+ st.error(f"Out of tries! Word was **{st.session_state.scramble_word}**")
98
+ del st.session_state.scramble_word
99
+ else:
100
+ st.warning("Try again!")
101
+ with col2:
102
+ st.info(f"๐Ÿ” Tries left: {st.session_state.scramble_attempts}")
103
 
104
  def emoji_quiz():
105
  st.subheader("๐Ÿ˜ Emoji Quiz")
 
116
  if st.button("Check Answer"):
117
  if guess.strip().lower() == st.session_state.emoji_answer.lower():
118
  st.success("Correct!")
 
119
  del st.session_state.emoji_question
120
  del st.session_state.emoji_answer
121
  else:
 
127
  if "hangman_word" not in st.session_state:
128
  st.session_state.hangman_word = random.choice(words)
129
  st.session_state.hangman_tries = 5
130
+ guess = st.text_input("Guess the word:")
131
  col1, col2 = st.columns(2)
132
+ with col1:
133
+ if st.button("Submit"):
134
+ st.session_state.hangman_tries -= 1
135
+ if guess.lower() == st.session_state.hangman_word:
136
+ st.success("Correct!")
137
+ del st.session_state.hangman_word
138
+ elif st.session_state.hangman_tries <= 0:
139
+ st.error(f"Game over! Word was {st.session_state.hangman_word}")
140
+ del st.session_state.hangman_word
141
+ else:
142
+ st.warning(f"Incorrect!")
143
+ with col2:
144
+ st.info(f"Tries left: {st.session_state.hangman_tries}")
145
 
146
  def math_quiz():
147
  st.subheader("โž• Math Quiz")
 
153
  if st.button("Submit"):
154
  if ans == st.session_state.a + st.session_state.b:
155
  st.success("Correct!")
 
 
 
156
  else:
157
  st.error(f"Wrong! Answer is {st.session_state.a + st.session_state.b}")
158
+ del st.session_state.a
159
+ del st.session_state.b
160
 
161
  def quick_typing():
162
+ st.subheader("โŒจ๏ธ Quick Typing")
163
  words = ["keyboard", "streamlit", "python", "arcade"]
164
  if "typing_word" not in st.session_state:
165
  st.session_state.typing_word = random.choice(words)
166
  st.session_state.start_time = time.time()
 
 
167
  st.info(f"Type this: **{st.session_state.typing_word}**")
168
  user = st.text_input("Start typing:")
 
169
  time_passed = time.time() - st.session_state.start_time
170
+ duration = len(st.session_state.typing_word) * 0.7
171
  st.write(f"โณ Time used: {int(time_passed)}s / {int(duration)}s")
 
172
  if st.button("Check"):
173
  if time_passed > duration:
174
+ st.error("โฐ Time exceeded!")
 
175
  elif user == st.session_state.typing_word:
176
  st.success("Perfect!")
 
177
  else:
178
  st.error("Incorrect!")
179
  del st.session_state.typing_word
180
 
181
+ def emoji_memory():
182
+ st.subheader("๐Ÿง  Emoji Memory Match")
183
+ emojis = random.sample(["๐Ÿ•", "๐ŸŽˆ", "๐Ÿถ", "๐Ÿš—", "๐ŸŽ", "๐ŸŒŸ"], 4)
184
+ if "emoji_mem" not in st.session_state:
185
+ st.session_state.emoji_mem = emojis
186
+ st.session_state.mem_start = datetime.now()
187
+ if (datetime.now() - st.session_state.mem_start).seconds < 5:
188
+ st.info("Memorize these:")
189
+ st.code(" ".join(st.session_state.emoji_mem))
190
+ else:
191
+ guess = st.text_input("Enter one emoji you remember:")
192
+ if st.button("Check"):
193
+ if guess.strip() in st.session_state.emoji_mem:
194
+ st.success("Correct!")
195
+ else:
196
+ st.error(f"Oops! Emojis were: {' '.join(st.session_state.emoji_mem)}")
197
+ del st.session_state.emoji_mem
198
 
199
  def tic_tac_toe():
200
  st.subheader("โŒ Tic Tac Toe")
201
+ st.write("โœ… Coming soon! Placeholder for a playable board.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
 
203
+ # Dispatcher
204
  if selected_game == "Rock Paper Scissors":
205
  rock_paper_scissors()
206
  elif selected_game == "Guess the Number":
 
209
  word_scramble()
210
  elif selected_game == "Emoji Quiz":
211
  emoji_quiz()
212
+ elif selected_game == "Hangman":
213
  hangman()
214
  elif selected_game == "Math Quiz":
215
  math_quiz()
216
+ elif selected_game == "Quick Typing":
217
  quick_typing()
218
+ elif selected_game == "Emoji Memory Match":
219
+ emoji_memory()
220
  elif selected_game == "Tic Tac Toe":
221
  tic_tac_toe()
222
 
 
223
  st.markdown("---")
224
+ st.markdown("<center>๐Ÿš€ Built with โค๏ธ for fun and feedback on LinkedIn!</center>", unsafe_allow_html=True)