Workshop › Sokoban › Step 19 of 29
On to the next level
What we are doing
When a level is solved, Space loads the next one, unless it was the last. Loading rebuilds everything from the text,
so moving on is one call.
```js
if (event.key === ' ' && solved() && level < LEVELS.length - 1) loadLevel(level + 1)
draw()
```
What it means
- Three conditions joined with
&& ("and"): the key is Space, the level is solved, and it is not the last one.
LEVELS.length - 1 is the index of the last level (2), because counting starts at 0.
Your turn
In the listener, above draw(), write the Space line. Press Run, solve the first level and press Space.
Skills: Game states, Keyboard and mouse input
← Solved! Which level? →
All steps
- A level written as text
- The canvas and the pen
- The warehouse floor
- A function that draws
- A name for every tile
- Read the walls
- Draw the walls
- Center the level
- The goals
- The boxes
- The player
- Two more levels
- One step
- Walk with the arrows
- Boxes are in the way
- Push a box
- A box on a goal turns green
- Solved!
- On to the next level
- Which level?
- A line at the bottom
- Count the moves
- A photo of the game
- A photo before every move
- Undo
- Restart
- A record for every level
- Show the record
- Build it yourself: count the pushes