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

Lesson 18: Play Button + GameStats class (Matthes Ch 14 ยง1)

Learning Intentions

Success Criteria

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

Right now your game ends and the window freezes. A real game shows a 'Play' button so the player can start again. Today we add one.

๐Ÿ‘ I Do โ€” Teacher Demo

Live-code GameStats class (extracts ships_left + adds game_active flag). Then the Button class โ€” a Rect with rendered text. Hook MOUSEBUTTONDOWN โ†’ _check_play_button.

๐Ÿค We Do โ€” Build Together

Class wires up click-to-start together. Play button shows on launch + after losing. Click โ†’ game resets, mouse hides, play begins.

๐Ÿš€ You Do โ€” Your Turn

Customise button colour + text. Extension: show a second button like 'HIGH SCORE'. Arcade quests cover MOUSEBUTTONDOWN + collidepoint.

  • Create game_stats.py with class GameStats โ€” reset_stats() sets ships_left + game_active
  • Create button.py with class Button โ€” a Rect + rendered text
  • Add self.play_button = Button(self, 'Play') to Game.__init__
  • Add MOUSEBUTTONDOWN handler โ†’ _check_play_button
  • On play click: reset stats, empty groups, create new fleet, hide mouse

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

Loading practice quests for this lesson...

Three tiers โ€” pick yours

Support

GameStats + Button skeletons pre-written

Core

build from scratch

Extension

animated button

Extensions

๐Ÿ“ Exit Ticket โ€” Coding Journal

Journal: explain the game_active flag โ€” why do we need it separate from ships_left?

Evidence of Learning

Game starts with Play button visible. Clicking it starts play. Dying shows it again.

โ† PreviousLesson L17โ†‘ HubAll LessonsNext โ†’Lesson L19