Workshop › Candy Crush-style Match 3 › Step 26 of 29
Without a limit the game never ends and the score means little. A game has 20 moves; only a swap that matches uses one. The moves left are written at the top right.
```js
const MOVES = 20
let movesLeft
movesLeft = MOVES
movesLeft -= 1
ctx.textAlign = 'right'
ctx.fillText('Moves ' + movesLeft, canvas.width - LEFT, 30)
```reset gives MOVES moves.movesLeft -= 1 comes after the "no match" check in trySwap, so a swap that bounces back is free.textAlign = 'right' makes the text end at the given x: the right edge of the grid.FALL write MOVES; under let score write let movesLeft.reset, under score = 0, write movesLeft = MOVES.trySwap, above chain = 0, write movesLeft -= 1.draw, under the Score line, write the two Moves lines.Skills: Game states
← Show the hint The end of a game →