Workshop › Candy Crush-style Match 3 › Step 27 of 29
The end of a game
What we are doing
When the moves are used up and the last cascade has landed, the game is over: a line says so, and a click starts a
new game.
```js
if (movesLeft === 0) {
if (phase === 'idle') reset()
return
}
if (movesLeft === 0 && phase === 'idle') {
ctx.textAlign = 'center'
ctx.fillText('No moves left! Click to play again', canvas.width / 2, 58)
}
```
What it means
- With no moves left, a click starts a new game once everything has settled, and does nothing else either way.
- The message is shown only when the game is really over.
Your turn
- Make the
movesLeft block the first lines of the click listener.
- In
draw, under the Moves line, write the message block.
Skills: Game states, Keyboard and mouse input
← Twenty moves Remember the best score →
All steps
- A place for the board
- A checkered grid
- The game loop
- A board of random gems
- Draw the gems
- Start without matches
- Click a gem
- Show the selection
- Swap two neighbours
- Find every match
- No match, no swap
- A score and a fresh start
- Clear the match
- Let the gems fall
- Two halves of a clear
- Wait before clearing
- Flash, and hands off
- Cascades
- Where a gem came from
- Slide down
- Out from under the top
- Is there any move?
- Never stuck
- A hint after five seconds
- Show the hint
- Twenty moves
- The end of a game
- Remember the best score
- Build it yourself: swipe to swap