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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access