1
Step 8 Game Over and Win
Tirsvad edited this page 2026-11-21 11:33:25 +01:00

English · Dansk · Bahasa Malaysia

Step 8: Game over and win

The GAME OVER message with the aliens at the ship

The YOU WIN message after the last alien was shot

What we built

The game is lost when an alien touches the ship or reaches the ship's row, and won when the last alien is shot. The pure function game_state decides, the Banner class writes GAME OVER or YOU WIN, and the keys stop working. The screenshots of this step come from prepared situations in tools/scenarios/.

What we gained

  • Describing the game as a state: playing, lost or won
  • Letting one function decide the state, so the rule is in one place
  • Stopping the frame loop and the keys when the game has ended
  • Preparing a situation in a script to take a screenshot of a rare moment

Try it

Let the aliens reach the ship, or shoot them all.

Where the code is

src/banner.py, src/game.py: check_state, src/rules.py: game_state

Previous: Barriers · Next: Score and lives · Overview