From 80ad07c7959021dbf3d4a5b50868d71996662200 Mon Sep 17 00:00:00 2001 From: Kevin Baumgartner Date: Fri, 8 May 2026 17:34:52 +0200 Subject: [PATCH 1/3] feat(highscore): add draw function in highscore --- src/highscore.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/highscore.py b/src/highscore.py index 71f443b..0d84f69 100644 --- a/src/highscore.py +++ b/src/highscore.py @@ -1,9 +1,14 @@ import json +import pygame +from settings import HIGHSCORE_COLOR_FONT, HIGHSCORE_COLOR_TABLE class Highscore: def __init__(self): # fix path to json file with highscores - self.path = "./highscore.json" + self.path = "src/highscore.json" + + self.font_title = pygame.font.SysFont("Arial", 28, bold=True) + self.font_score = pygame.font.SysFont("Arial", 18, bold=True) # check if file already exists, otherwise create it try: @@ -89,4 +94,43 @@ class Highscore: formatted_scores.append(line) - return formatted_scores \ No newline at end of file + return formatted_scores + + def draw(self, screen, x, y): + # draw box background + box_rect = pygame.Rect(x, y, 500, 300) + pygame.draw.rect(screen, HIGHSCORE_COLOR_TABLE, box_rect, border_radius=12) + pygame.draw.rect(screen, HIGHSCORE_COLOR_TABLE, box_rect, border_radius=12) + + # title + title = self.font_title.render( + "ECTS Leaderboard", + True, + HIGHSCORE_COLOR_FONT + ) + screen.blit(title, (x + 20, y + 20)) + + # Get highscore lines + highscore_lines = self.get_top_scores_formatted() + + + if len(highscore_lines) == 0: + no_scores_text = self.font_score.render( + "No students ranked yet.", + True, + HIGHSCORE_COLOR_FONT + ) + screen.blit(no_scores_text, (x + 20, y + 70)) + return + + # Draw scores + score_y = y + 70 + + for line in highscore_lines: + score_text = self.font_score.render( + line, + True, + HIGHSCORE_COLOR_FONT + ) + screen.blit(score_text, (x + 20, score_y)) + score_y += 35 From 7833d381a610a310a47594ec4617279733e1a811 Mon Sep 17 00:00:00 2001 From: Kevin Baumgartner Date: Fri, 8 May 2026 17:37:30 +0200 Subject: [PATCH 2/3] feat(startscreen): add highscore table in start screen --- src/settings.py | 4 ++++ src/startscreen.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/settings.py b/src/settings.py index fb68e0a..0a16848 100644 --- a/src/settings.py +++ b/src/settings.py @@ -119,3 +119,7 @@ HUD_BAR_X = 150 # left startpoint for hp bars HUD_Y_DOOR = 20 HUD_Y_ZOMBIE = 50 HUD_Y_ECTS = 85 + +# --- HIGHSCORE --- +HIGHSCORE_COLOR_FONT = (0, 0, 0) +HIGHSCORE_COLOR_TABLE = (150, 255, 0) diff --git a/src/startscreen.py b/src/startscreen.py index fddb731..6002407 100644 --- a/src/startscreen.py +++ b/src/startscreen.py @@ -8,6 +8,7 @@ from src.settings import ( COLOR_STARTSCREEN_FONT_LABEL, ) from src.text_input import TextInput +from src.highscore import Highscore class Startscreen: def __init__(self, screen): @@ -42,6 +43,8 @@ class Startscreen: 20, 310) + self.highscore = Highscore() + def run(self): # set background color self.screen.fill(COLOR_STARTSCREEN_BACKGROUND) @@ -70,6 +73,9 @@ class Startscreen: label_input_error = self.font_label.render("Student not found. Please enter valid name/id.", True, (255, 0, 0)) + # draw highscore table + self.highscore.draw(self.screen, 560, 90) + # get all events events = pygame.event.get() From 810a44c904475a21a8e2cae7b3481197d99d5534 Mon Sep 17 00:00:00 2001 From: Niklas Haiden Date: Fri, 8 May 2026 17:41:45 +0200 Subject: [PATCH 3/3] fix: import error --- src/highscore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/highscore.py b/src/highscore.py index 0d84f69..625b8e9 100644 --- a/src/highscore.py +++ b/src/highscore.py @@ -1,6 +1,6 @@ import json import pygame -from settings import HIGHSCORE_COLOR_FONT, HIGHSCORE_COLOR_TABLE +from src.settings import HIGHSCORE_COLOR_FONT, HIGHSCORE_COLOR_TABLE class Highscore: def __init__(self):