H a n d s o n, p r o j e c t b a s e d
Download 4.21 Mb. Pdf ko'rish
|
Python Crash Course, 2nd Edition
Resetting the Speed
Now we need to return any changed settings to their initial values each time the player starts a new game; otherwise, each new game would start with the increased speed settings of the previous game: def _check_play_button(self, mouse_pos): """Start a new game when the player clicks Play.""" button_clicked = self.play_button.rect.collidepoint(mouse_pos) if button_clicked and not self.stats.game_active: # Reset the game settings. self.settings.initialize_dynamic_settings() --snip-- Playing Alien Invasion should be more fun and challenging now. Each time you clear the screen, the game should speed up and become slightly more difficult. If the game becomes too difficult too quickly, decrease the value of settings.speedup_scale . Or if the game isn’t challenging enough, increase the value slightly. Find a sweet spot by ramping up the difficulty in a reasonable amount of time. The first couple of screens should be easy, the next few challenging but doable, and subsequent screens almost impossibly difficult. settings.py alien_invasion.py alien_invasion.py 288 Chapter 14 Try iT yourSelf 14-3. Challenging Target Practice: Start with your work from Exercise 14-2 (page 285). 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 : class GameStats: --snip-- def reset_stats(self): """Initialize statistics that can change during the game.""" self.ships_left = self.ai_settings.ship_limit self.score = 0 To reset the score each time a new game starts, we initialize score in reset_stats() rather than __init__() . Download 4.21 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling