Implement Score API Client and User Profile Integration
- Added ScoreAPIClient for communication with the Mice Game Score API, including methods for user signup, score submission, and leaderboard retrieval. - Developed a simple profile manager demo to showcase user profile management and API integration. - Created a test script for the Score API to validate all endpoints and functionality. - Introduced UserProfileIntegration to manage user profiles, including local storage and API synchronization. - Added a JSON file for user profiles with sample data for testing and demonstration purposes.
This commit is contained in:
+35
-15
@@ -200,32 +200,52 @@ class GameWindow:
|
||||
self.target_size[0] - 100, self.target_size[1] - 100,
|
||||
"win", filling=(255, 255, 255))
|
||||
|
||||
# Draw main text
|
||||
self.draw_text(text, self.fonts[self.target_size[1]//20], "center", sdl2.ext.Color(0, 0, 0))
|
||||
# Calculate layout positions to avoid overlaps
|
||||
title_y = self.target_size[1] // 4 # Title at 1/4 of screen height
|
||||
|
||||
# Draw subtitle if provided
|
||||
if subtitle := kwargs.get("subtitle"):
|
||||
self.draw_text(subtitle, self.fonts[self.target_size[1]//30],
|
||||
("center", self.target_size[1] // 2 + 50), sdl2.ext.Color(0, 0, 0))
|
||||
# Draw main text (title)
|
||||
self.draw_text(text, self.fonts[self.target_size[1]//20],
|
||||
("center", title_y), sdl2.ext.Color(0, 0, 0))
|
||||
|
||||
# Draw image if provided
|
||||
# Draw image if provided - position it below title
|
||||
image_bottom_y = title_y + 60 # Default position if no image
|
||||
if image := kwargs.get("image"):
|
||||
image_size = self.get_image_size(image)
|
||||
image_y = title_y + 50
|
||||
self.draw_image(self.target_size[0] // 2 - image_size[0] // 2 - self.w_offset,
|
||||
self.target_size[1] // 2 - image_size[1] * 2 - self.h_offset,
|
||||
image_y - self.h_offset,
|
||||
image, "win")
|
||||
image_bottom_y = image_y + image_size[1] + 20
|
||||
|
||||
# Draw scores if provided
|
||||
# Draw subtitle if provided - handle multi-line text, position below image
|
||||
if subtitle := kwargs.get("subtitle"):
|
||||
subtitle_lines = subtitle.split('\n')
|
||||
base_y = image_bottom_y + 20
|
||||
line_height = 25 # Fixed line height for consistent spacing
|
||||
|
||||
for i, line in enumerate(subtitle_lines):
|
||||
if line.strip(): # Only draw non-empty lines
|
||||
self.draw_text(line.strip(), self.fonts[self.target_size[1]//35],
|
||||
("center", base_y + i * line_height), sdl2.ext.Color(0, 0, 0))
|
||||
|
||||
# Draw scores if provided - position at bottom
|
||||
if scores := kwargs.get("scores"):
|
||||
sprite = self.factory.from_text("Scores:", color=sdl2.ext.Color(0, 0, 0),
|
||||
fontmanager=self.fonts[self.target_size[1]//20])
|
||||
sprite.position = (self.target_size[0] // 2 - 50, self.target_size[1] // 2 + 30)
|
||||
scores_start_y = self.target_size[1] * 3 // 4 # Bottom quarter of screen
|
||||
sprite = self.factory.from_text("High Scores:", color=sdl2.ext.Color(0, 0, 0),
|
||||
fontmanager=self.fonts[self.target_size[1]//25])
|
||||
sprite.position = (self.target_size[0] // 2 - sprite.size[0] // 2, scores_start_y)
|
||||
self.renderer.copy(sprite, dstrect=sprite.position)
|
||||
|
||||
for i, score in enumerate(scores[:5]):
|
||||
score_text = " - ".join(score)
|
||||
self.draw_text(score_text, self.fonts[self.target_size[1]//40],
|
||||
("center", self.target_size[1] // 2 + 50 + 30 * (i + 1)),
|
||||
if len(score) >= 4: # New format: date, score, name, device
|
||||
score_text = f"{score[2]}: {score[1]} pts ({score[3]})"
|
||||
elif len(score) >= 3: # Medium format: date, score, name
|
||||
score_text = f"{score[2]}: {score[1]} pts"
|
||||
else: # Old format: date, score
|
||||
score_text = f"Guest: {score[1]} pts"
|
||||
|
||||
self.draw_text(score_text, self.fonts[self.target_size[1]//45],
|
||||
("center", scores_start_y + 30 + 25 * (i + 1)),
|
||||
sdl2.ext.Color(0, 0, 0))
|
||||
|
||||
def start_dialog(self, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user