Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python (蟒蛇课程)外星人入侵高分_Python_Python 3.x_Pygame - Fatal编程技术网

Python (蟒蛇课程)外星人入侵高分

Python (蟒蛇课程)外星人入侵高分,python,python-3.x,pygame,Python,Python 3.x,Pygame,到目前为止,我的项目的最高分是有效的,但是,在我的飞船被击中后,当前的分数不会自动重置。例如,如果我得到4000分,我的飞船被击中,在下一轮中,最高分和当前分数显示为4000分 game_stats.py: class GameStats(): def __init__(self, ai_settings): self.ai_settings = ai_settings self.reset_stats()

到目前为止,我的项目的最高分是有效的,但是,在我的飞船被击中后,当前的分数不会自动重置。例如,如果我得到4000分,我的飞船被击中,在下一轮中,最高分和当前分数显示为4000分

game_stats.py:

    class GameStats():
         def __init__(self, ai_settings):
              self.ai_settings = ai_settings
              self.reset_stats()
              self.game_active = False
              self.high_score = 0

         def reset_stats(self):
              self.ships_left = self.ai_settings.ship_limit
              self.score = 0
scoreboard.py:

    def show_score(self):
         self.screen.blit(self.score_image, self.score_rect)
         self.screen.blit(self.high_score_image, self.high_score_rect)
    def prep_high_score(self):
         high_score = int(round(self.stats.high_score, -1))
         high_score_str = "{:,}".format(high_score)
         self.high_score_image = self.font.render(high_score_str, True, self.text_color, 
              self.ai_settings.bg_color)
         self.high_score_rect = self.high_score_image.get_rect()
         self.high_score_rect.centerx = self.screen_rect.centerx
         self.high_score_rect.top = self.score_rect.top
game_functions.py:

    def check_high_score(stats, sb):
         if stats.score > stats.high_score:
             stats.high_score = stats.score
             sb.prep_high_score()
    def check_play_button(ai_settings, screen, stats, play_button, ship, 
    aliens, bullets, mouse_x, mouse_y):
         button_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
         if button_clicked and not stats.game_active:
              ai_settings.initialize_dynamic_settings()
              pygame.mouse.set_visible(False)
              stats.reset_stats()
              stats.game_active = True
              aliens.empty()
              bullets.empty()
              create_fleet(ai_settings, screen, ship, aliens)
              ship.center_ship()

这是《Python速成课程》一书中的一个项目,对吗?如果是这样的话,你的代码是好的,分数应该只在你的飞船被击中3次(飞船数量限制)时重置,而不是在第一次或第二次击中时重置。

除了
游戏统计信息的内部。

你在哪里调用
重置统计信息
?我还在游戏函数中调用了它,我刚刚在上面的模块中编辑了这些函数,尽可能地向我们展示了,这还不足以成为一个可复制的例子