Coin Quest: Game Over
🪙 The last piece. Right now, crashing just freezes everything — no message, no second chance.
Remember the very first Coin Quest exercise, back in the Variables chapter? You
made three variables: player, score, and is_playing. You've been carrying
score and is_playing ever since. Here's where is_playing finally earns its
keep.
1. Write hud(state). It returns the line of text shown under the game.
- Still playing →
Coins: 3 - Game over →
GAME OVER - Coins: 3 - press R
Remember str() — you can't join a number onto text without it.
2. Add restart. Make the very first line of update:
if keys["r"]:
return new_game()Returning a brand-new state wipes everything — position, rocks, coins, score —
in one line. That's why new_game() was worth writing as a function.
Crash on purpose. Read the message. Press R. Go again.
🎉 That's Coin Quest — a real game, built from print statements up.
1/0/Coins: 0 1/0/Coins: 0 1/0/Coins: 0 1/0/Coins: 0 1/0/Coins: 0 1/0/Coins: 0 1/0/Coins: 0 0/0/GAME OVER - Coins: 0 - press R 0/0/GAME OVER - Coins: 0 - press R 1/0/Coins: 0 1/0/Coins: 0 1/0/Coins: 0