Workshop › Sokoban › Step 22 of 29
A move counter shows how good a solution is. Every step that really happens adds one; blocked steps do not count.
```js
let moves
function loadLevel(index) {
// ...
moves = 0
}
function move(dx, dy) {
// ...
player = { x, y }
moves += 1
}
ctx.textAlign = 'right'
ctx.fillText('Moves: ' + moves, canvas.width - 12, TOP / 2)
```moves starts at 0 on every load.moves += 1 comes after player = { x, y }: blocked steps have already returned, so they are not counted.textAlign = 'right' puts the end of the text at x, 12 pixels from the right edge.let player write let moves.loadLevel write moves = 0; at the end of move, under player = { x, y }, write moves += 1.draw, under the Level line, write the two lines. Press Run.Skills: Game states
← A line at the bottom A photo of the game →