счет не отображается / накапливается в Alien_invasion - PullRequest
0 голосов
/ 19 октября 2018

Я работаю над игрой о вторжении инопланетян в ускоренный курс по питону и попал на табло.Я не вижу ошибок в своем коде, но не могу понять, почему мой счет не отображается.Игра работает нормально, но когда пришёл инопланетянин, счёт не добавляется.Как только инопланетянин попал, счет должен увеличиваться.Вот игра:

# Create an instance to store game statistics and create a scoreboard.
stats = GameStats(ai_settings)
sb = Scoreboard(ai_settings, screen, stats)

# Start the main loop for the game.
while True:
    gf.check_events(ai_settings, screen, stats, play_button, ship, aliens, bullets)

    if stats.game_active:
        ship.update()
        gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
        gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)

    gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)

run_game()  

Вот табло.py:

    import pygame.font

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 image.
    self.prep_score()

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

def show_score(self):
    """ Draw score to the screen. """
    self.screen.blit(self.score_image, self.score_rect)

Вот мои настройки.py:

def initialize_dynamic_settings(self):

    # Scoring
    self.alien_points = 50

def increase_speed(self):
    """ Increase speed setttings and alien point values. """
    self.ship_speed_factor *= self.speedup_scale
    self.bullet_speed_factor *= self.speedup_scale
    self.alien_speed_factor *= self.speedup_scale

    self.alien_points = int(self.alien_points * self.score_scale)
    #print(self.alien_points)

А вот и мои игровые функции:

    def update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button):

# Draw the score information
sb.show_score()


check_bullet_alien_collisions(ai_settings, screen, stats, sb, ship, aliens, bullets)

def check_bullet_alien_collisions(ai_settings, screen, stats, sb, ship, aliens, bullets):
""" Respond to bullet-alien collisions. """
# Remove any bullets and aliens that have collided.
collisions = pygame.sprite.groupcollide(bullets, aliens, True, True)

if collisions:
    for aliens in collisions.values():
        stats.score += ai_settings.alien_points * len(aliens)
        sb.prep_score
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...