diff --git a/scoreboard.py b/scoreboard.py new file mode 100644 index 0000000..e72b52d --- /dev/null +++ b/scoreboard.py @@ -0,0 +1,38 @@ +import pygame.font +from pygame.sprite import Group + +from ship import Ship + +class Scoreboard(): + """A class to report scoring information.""" + + def __init__(self, ai_settings, screen, stats): + """Initialize scorekeeping attributes.""" + self.screen = screen + self.screen_rect = screen.get_rect() + self.ai_settings = ai_settings + self.stats = stats + + # Font settings for scoring information. + self.text_color = (30, 30, 30) + self.font = pygame.font.SysFont(None, 48) + + # Prepare the initial score images. + self.prep_score() + self.prep_high_score() + self.prep_level() + self.prep_ships() + + def prep_score(self): + """Turn the score into a rendered image.""" + rounded_score = int(round(self.stats.score, -1)) + score_str = "{:,}".format(rounded_score) + self.score_image = self.font.render(score_str, True, self.text_color, + self.ai_settings.bg_color) + + # Display the score at the top right of the screen. + self.score_rect = self.score_image.get_rect() + self.score_rect.right = self.screen_rect.right - 20 + self.score_rect.top = 20 + + \ No newline at end of file