Task: MIL-003#1 Task: MIL-003#2 Task: MIL-003#3 Task: MIL-003#4 Task: MIL-003#5 Task: MIL-003#6
29 lines
1.4 KiB
Markdown
29 lines
1.4 KiB
Markdown
**English** · [Dansk](Step-8-Game-Over-and-Win-da) · [Bahasa Malaysia](Step-8-Game-Over-and-Win-ms)
|
|
|
|
# Step 8: Game over and win
|
|
|
|

|
|
|
|

|
|
|
|
## 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](Step-7-Barriers) · Next: [Score and lives](Step-9-Score-and-Lives) · [Overview](Home)
|