Files changed (1) hide show
  1. app.py +22 -88
app.py CHANGED
@@ -111,7 +111,7 @@ def join_game():
111
  else:
112
  st.error("Invalid Game ID. Please check and try again.")
113
 
114
- # Function to start the game
115
  def start_game(game_data):
116
  topics = game_data['topics']
117
  questions = game_data['questions']
@@ -171,102 +171,38 @@ def start_game(game_data):
171
 
172
  st.success(f"Game Over! Your final score is {score}")
173
 
174
- # Function to display the leaderboard with animations
175
- def display_dashboard():
 
176
  leaderboard_df = load_leaderboard()
 
177
 
178
- st.subheader("Top 3 Players")
179
- top_3 = leaderboard_df.head(3)
180
-
181
- # First Place Winner - Celebration Animation
182
- first_place = top_3.iloc[0] if not leaderboard_df.empty else None
183
- if first_place is not None:
184
- st.write(f"πŸ† {first_place['name']} - {first_place['score']} points! πŸŽ‰ {first_place['avatar']}")
185
- st.markdown("<h3 style='color: gold;'>πŸŽ‰ Congratulations on First Place! πŸŽ‰</h3>", unsafe_allow_html=True)
186
- html_code = f"""
187
- <div style="text-align: center;">
188
- <h2>πŸ† Winner: {first_place['name']} πŸ†</h2>
189
- <p>Score: {first_place['score']}</p>
190
- <p>Avatar: {first_place['avatar']}</p>
191
- </div>
192
- <div id="balloon" style="position: absolute; top: 50%; left: 50%; animation: float 2s infinite;">
193
- πŸŽˆπŸŽ‰
194
- </div>
195
- <style>
196
- @keyframes float {{
197
- 0% {{ transform: translateY(0); }}
198
- 50% {{ transform: translateY(-50px); }}
199
- 100% {{ transform: translateY(0); }}
200
- }}
201
- </style>
202
- """
203
- html(html_code)
204
-
205
- # Second Place Winner - Celebration Animation
206
- if len(top_3) > 1:
207
- second_place = top_3.iloc[1]
208
- st.write(f"πŸ₯ˆ {second_place['name']} - {second_place['score']} points! {second_place['avatar']}")
209
- st.markdown("<h3 style='color: silver;'>πŸ‘ Congratulations on Second Place! πŸ‘</h3>", unsafe_allow_html=True)
210
- html_code = f"""
211
- <div style="text-align: center;">
212
- <h2>πŸ₯ˆ Runner-up: {second_place['name']} πŸ₯ˆ</h2>
213
- <p>Score: {second_place['score']}</p>
214
- <p>Avatar: {second_place['avatar']}</p>
215
- </div>
216
- <div style="animation: clap 1s linear infinite;">
217
- πŸ‘πŸ‘πŸ‘
218
- </div>
219
- <style>
220
- @keyframes clap {{
221
- 0% {{ transform: scale(1); }}
222
- 50% {{ transform: scale(1.2); }}
223
- 100% {{ transform: scale(1); }}
224
- }}
225
- </style>
226
- """
227
- html(html_code)
228
 
229
- # Third Place Winner - Celebration Animation
230
- if len(top_3) > 2:
231
- third_place = top_3.iloc[2]
232
- st.write(f"πŸ₯‰ {third_place['name']} - {third_place['score']} points! {third_place['avatar']}")
233
- st.markdown("<h3 style='color: #cd7f32;'>πŸ‘ Nice Try on Third Place! πŸ‘</h3>", unsafe_allow_html=True)
234
  html_code = f"""
235
  <div style="text-align: center;">
236
- <h2>πŸ₯‰ Third Place: {third_place['name']} πŸ₯‰</h2>
237
- <p>Score: {third_place['score']}</p>
238
- <p>Avatar: {third_place['avatar']}</p>
239
  </div>
240
- <div style="animation: thumbsUp 1s linear infinite;">
241
- πŸ‘
242
  </div>
243
  <style>
244
- @keyframes thumbsUp {{
245
- 0% {{ transform: rotate(0deg); }}
246
- 50% {{ transform: rotate(20deg); }}
247
- 100% {{ transform: rotate(0deg); }}
248
  }}
249
  </style>
250
  """
251
  html(html_code)
252
 
253
- # Pie chart for the distribution of player scores
254
- fig = go.Figure(data=[go.Pie(labels=leaderboard_df['name'], values=leaderboard_df['score'], hole=0.3)])
255
- fig.update_layout(title="Score Distribution")
256
- st.plotly_chart(fig)
257
-
258
- # Bar chart of leaderboard rankings
259
- fig = px.bar(
260
- leaderboard_df,
261
- x='name',
262
- y='score',
263
- color='name',
264
- title="Leaderboard",
265
- labels={'name': 'Player', 'score': 'Score'},
266
- hover_data=["avatar"]
267
- )
268
- st.plotly_chart(fig)
269
-
270
  # Main function to handle Streamlit app
271
  def main():
272
  st.title('AI Quiz Game')
@@ -274,9 +210,7 @@ def main():
274
  mode = st.sidebar.selectbox("Select Mode", ["Home", "Create Game", "Join Game", "Leaderboard"])
275
 
276
  if mode == "Home":
277
- st.write("Welcome to the Game!")
278
- st.write("You can create a new game, join an existing game, or check the leaderboard.")
279
- display_dashboard()
280
 
281
  elif mode == "Create Game":
282
  create_game()
@@ -285,7 +219,7 @@ def main():
285
  join_game()
286
 
287
  elif mode == "Leaderboard":
288
- display_dashboard()
289
 
290
  if __name__ == "__main__":
291
  main()
 
111
  else:
112
  st.error("Invalid Game ID. Please check and try again.")
113
 
114
+ # Function to start the game when all players have joined
115
  def start_game(game_data):
116
  topics = game_data['topics']
117
  questions = game_data['questions']
 
171
 
172
  st.success(f"Game Over! Your final score is {score}")
173
 
174
+ # Function to display recent players and cracker animations
175
+ def display_homepage():
176
+ # Display recent winners from the leaderboard file
177
  leaderboard_df = load_leaderboard()
178
+ recent_winners = leaderboard_df.tail(5) # Show the most recent winners (up to 5)
179
 
180
+ st.subheader("Recent Winners")
181
+ for index, winner in recent_winners.iterrows():
182
+ st.write(f"{winner['name']} - {winner['score']} points - Avatar: {winner['avatar']}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
+ # Celebration for the first winner with cracker animation
185
+ first_winner = recent_winners.iloc[-1] if not recent_winners.empty else None
186
+ if first_winner is not None:
187
+ st.markdown("<h3 style='color: gold;'>πŸŽ‰ Congratulations to the First Winner! πŸŽ‰</h3>", unsafe_allow_html=True)
 
188
  html_code = f"""
189
  <div style="text-align: center;">
190
+ <h2>πŸ† {first_winner['name']} πŸ†</h2>
191
+ <p>Score: {first_winner['score']}</p>
192
+ <p>Avatar: {first_winner['avatar']}</p>
193
  </div>
194
+ <div id="fireworks" style="position: absolute; top: 50%; left: 50%; animation: fireworks 2s infinite;">
195
+ πŸŽ†πŸŽ‡
196
  </div>
197
  <style>
198
+ @keyframes fireworks {{
199
+ 0% {{ transform: scale(0); opacity: 1; }}
200
+ 100% {{ transform: scale(3); opacity: 0; }}
 
201
  }}
202
  </style>
203
  """
204
  html(html_code)
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  # Main function to handle Streamlit app
207
  def main():
208
  st.title('AI Quiz Game')
 
210
  mode = st.sidebar.selectbox("Select Mode", ["Home", "Create Game", "Join Game", "Leaderboard"])
211
 
212
  if mode == "Home":
213
+ display_homepage()
 
 
214
 
215
  elif mode == "Create Game":
216
  create_game()
 
219
  join_game()
220
 
221
  elif mode == "Leaderboard":
222
+ display_homepage()
223
 
224
  if __name__ == "__main__":
225
  main()