0% found this document useful (0 votes)
8 views1 page

Scoring System for Alien Invasion Game

Uploaded by

darkflux514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Scoring System for Alien Invasion Game

Uploaded by

darkflux514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TRY IT YOURSELF

14-3. Challenging Target Practice: Start with your work from Exercise 14-2
(page 283). Make the target move faster as the game progresses, and restart
the target at the original speed when the player clicks Play.
14-4. Difficulty Levels: Make a set of buttons for Alien Invasion that allows the
player to select an appropriate starting difficulty level for the game. Each but-
ton should assign the appropriate values for the attributes in Settings needed
to create different difficulty levels.

Scoring
Let’s implement a scoring system to track the game’s score in real time and
display the high score, level, and number of ships remaining.
The score is a game statistic, so we’ll add a score attribute to GameStats:

game_stats.py class GameStats:


--snip--
def reset_stats(self):
"""Initialize statistics that can change during the game."""
self.ships_left = self.ai_settings.ship_limit
[Link] = 0

To reset the score each time a new game starts, we initialize score in
reset_stats() rather than __init__().

Displaying the Score


To display the score on the screen, we first create a new class, Scoreboard. For
now, this class will just display the current score. Eventually, we’ll use it to
report the high score, level, and number of ships remaining as well. Here’s
the first part of the class; save it as [Link]:

[Link] import [Link]

class Scoreboard:
"""A class to report scoring information."""

1 def __init__(self, ai_game):


"""Initialize scorekeeping attributes."""
[Link] = ai_game.screen
self.screen_rect = [Link].get_rect()
[Link] = ai_game.settings
[Link] = ai_game.stats

# Font settings for scoring information.


2 self.text_color = (30, 30, 30)
3 [Link] = [Link](None, 48)

286 Chapter 14

You might also like