Cover by Marijn Haverbeke

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Example: Implementing Sokoban

Armed with addHandler and the dom function from the previous chapter, we are ready for more challenging feats of document manipulation. As an exercise, we will implement the game known as Sokoban. This is something of a classic, but you may not have seen it before. The rules are these: There is a grid made up of walls, empty space, and one or more “exits.” On this grid, there are a number of crates or stones, and a little dude that the player controls. This dude can be moved horizontally and vertically into empty squares and can push the boulders around, provided that there is empty space behind them. The goal of the game is to move a given number of boulders into the exits. It looks something like this:

Level Input ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required