<gh_stars>0
import pygame.font
from pygame.sprite import Group

from player.ship import Ship

white = (255, 255, 255)
green = (0, 255, 0)


class Scoreboard:

    def __init__(self, settings, screen, stats, alien_fleet, bullets):
        self.settings = settings
        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.stats = stats
        self.alien_fleet = alien_fleet
        self.bullets = bullets
        self.font = pygame.font.Font('assets/fonts/space_invaders.ttf', 16)
        self.level_image = self.level_image_1 = self.level_rect = self.level_rect_1 = None
        self.score_image = self.score_image_1 = self.score_rect = self.score_rect_1 = None
        self.ship_lives = self.ship_rect = None
        self.ships = Group()
        self.update()

    def update_level(self):
        self.level_image = self.font.render('LEVEL     ', True, white)
        self.level_rect = self.level_image.get_rect()
        self.level_rect.topleft = 10, 10
        self.level_image_1 = self.font.render(str(self.stats.level), True, green)
        self.level_rect_1 = self.level_image_1.get_rect()
        self.level_rect_1.topleft = self.level_rect.width, self.level_rect.top

    def update_score(self):
        self.score_image = self.font.render('SCORE     ', True, white)
        self.score_rect = self.score_image.get_rect()
        self.score_rect.topleft = 10, self.level_rect.bottom + 5
        rounded_score = int(round(self.stats.score, -1))
        score = "{:,}".format(rounded_score)
        self.score_image_1 = self.font.render(score, True, green)
        self.score_rect_1 = self.score_image.get_rect()
        self.score_rect_1.topleft = self.score_rect.width, self.score_rect.top

    def update_lives(self):
        self.ship_lives = self.font.render('LIVES   ', True, white)
        self.ship_rect = self.ship_lives.get_rect()
        self.ship_rect.topleft = 10, self.score_rect_1.bottom + 5
        self.ships.empty()
        for ship_index in range(self.stats.ships_remaining):
            ship = Ship(self.settings, self.screen, self.stats, self, None,
                        self.alien_fleet, self.bullets, None, (22, 20))
            ship.rect.x = self.ship_rect.width + 5 + (5 + ship.rect.width) * ship_index
            ship.rect.y = self.score_rect_1.bottom + 4
            self.ships.add(ship)

    def update(self):
        """Updates file values prior to rendering."""
        self.update_level()
        self.update_score()
        self.update_lives()

    def draw(self):
        self.screen.blit(self.level_image, self.level_rect)
        self.screen.blit(self.level_image_1, self.level_rect_1)
        self.screen.blit(self.score_image, self.score_rect)
        self.screen.blit(self.score_image_1, self.score_rect_1)
        self.screen.blit(self.ship_lives, self.ship_rect)
        self.ships.draw(self.screen)

import pygame.font
from pygame.sprite import Group

from player.ship import Ship

white = (255, 255, 255)
green = (0, 255, 0)


class Scoreboard:

    def __init__(self, settings, screen, stats, alien_fleet, bullets):
        self.settings = settings
        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.stats = stats
        self.alien_fleet = alien_fleet
        self.bullets = bullets
        self.font = pygame.font.Font('assets/fonts/space_invaders.ttf', 16)
        self.level_image = self.level_image_1 = self.level_rect = self.level_rect_1 = None
        self.score_image = self.score_image_1 = self.score_rect = self.score_rect_1 = None
        self.ship_lives = self.ship_rect = None
        self.ships = Group()
        self.update()

    def update_level(self):
        self.level_image = self.font.render('LEVEL     ', True, white)
        self.level_rect = self.level_image.get_rect()
        self.level_rect.topleft = 10, 10
        self.level_image_1 = self.font.render(str(self.stats.level), True, green)
        self.level_rect_1 = self.level_image_1.get_rect()
        self.level_rect_1.topleft = self.level_rect.width, self.level_rect.top

    def update_score(self):
        self.score_image = self.font.render('SCORE     ', True, white)
        self.score_rect = self.score_image.get_rect()
        self.score_rect.topleft = 10, self.level_rect.bottom + 5
        rounded_score = int(round(self.stats.score, -1))
        score = "{:,}".format(rounded_score)
        self.score_image_1 = self.font.render(score, True, green)
        self.score_rect_1 = self.score_image.get_rect()
        self.score_rect_1.topleft = self.score_rect.width, self.score_rect.top

    def update_lives(self):
        self.ship_lives = self.font.render('LIVES   ', True, white)
        self.ship_rect = self.ship_lives.get_rect()
        self.ship_rect.topleft = 10, self.score_rect_1.bottom + 5
        self.ships.empty()
        for ship_index in range(self.stats.ships_remaining):
            ship = Ship(self.settings, self.screen, self.stats, self, None,
                        self.alien_fleet, self.bullets, None, (22, 20))
            ship.rect.x = self.ship_rect.width + 5 + (5 + ship.rect.width) * ship_index
            ship.rect.y = self.score_rect_1.bottom + 4
            self.ships.add(ship)

    def update(self):
        """Updates file values prior to rendering."""
        self.update_level()
        self.update_score()
        self.update_lives()

    def draw(self):
        self.screen.blit(self.level_image, self.level_rect)
        self.screen.blit(self.level_image_1, self.level_rect_1)
        self.screen.blit(self.score_image, self.score_rect)
        self.screen.blit(self.score_image_1, self.score_rect_1)
        self.screen.blit(self.ship_lives, self.ship_rect)
        self.ships.draw(self.screen)
Updates file values prior to rendering.