L21 ยท T2 Week 11 ๐ŸŽฏ CT5-DPM-01 ยท CT5-DAT-01 ๐Ÿ“‚ Phase 2 โ€” Alien Invasion ยท Ch 14 Scoring + End

Lesson 21: High Scores + Level + Ships Remaining (Matthes Ch 14 ยง5-7)

Learning Intentions

Success Criteria

๐Ÿ“ Do Now โ€” Error of the Day

Your Alien Invasion is feature-complete except for one thing: when you close the game, your top score VANISHES. Who remembers what the highest score was last lesson?

๐Ÿ‘ I Do โ€” Teacher Demo

Live-code high score persistence. json.dump(self.stats.high_score, open('high_score.json', 'w')). Load with try/except FileNotFoundError. Extend Scoreboard with prep_high_score, prep_level, and prep_ships (reuses Ship as life icons).

๐Ÿค We Do โ€” Build Together

Class adds all 3 HUD elements. Full HUD: score top-right, high score top-centre, level under score, lives top-left as ship icons.

๐Ÿš€ You Do โ€” Your Turn

Beat your own high score. Close the game โ€” reopen โ€” check that high_score.json persists. Open it in VS Code to see the number. Arcade quests cover json file I/O.

  • Add self.high_score = 0 + load from high_score.json in GameStats
  • Add _save_high_score() using json.dump
  • Extend Scoreboard: prep_high_score, prep_level, prep_ships (reuses Ship class)
  • Update high score on every score change
  • In show_score: blit all four (score, high_score, level, ships)

๐ŸŽฎ Practice Quests โ€” work through these

Loading practice quests for this lesson...

Three tiers โ€” pick yours

Support

prep_* methods scaffolded; json helpers pre-written

Core

build from scratch

Extension

top 5 leaderboard

Extensions

๐Ÿ“ Exit Ticket โ€” Coding Journal

Journal: describe what's in your high_score.json file. Why is it a text file, not binary? What else could we save there?

Evidence of Learning

Full HUD: score + high score + level + ship icons. high_score.json persists across runs.

โ† PreviousLesson L20โ†‘ HubAll LessonsNext โ†’Lesson L22