Sokoban
written by Mark Overmars

Goal
Sokoban is an old Japanse games. The goal is to move the objects (the balls) to the goal positions (the blue holes). You operate the mover using the arrow keys on your keyboard. You can only push a ball to the next position if that position is empty. You have solved the puzzle when all balls lie on holes. This is much harder than it sounds.

Playing
You move the pusher using the arrow keys. When you pushed a ball to a wrong place you can press the undo button at the top right to go one push back.

Levels
This version of the game contains the 50 standard levels. These are copyrighted by Thinking Rabbit and may only be played in countries were the original Sokoban game is not being sold. You can move between the levels using the red arrows at the top. You can restart the current level by pressing the button with the green arrows.

Design
Many (freeware) implementations of Sokoban exist. I don't claim that this is the nicest one, although it is not far off from the others. But is was very simple to created. There are just a handful of objects. There are a few issues though: 

•	The first issues is how to determine that the level is finished. This is rather trivial. We simply check whether each goal collides with a ball. This can be done in one action. 
•	Secondly, there is the issue of how to determine that the ball can move. This means that we have to look after the ball, in the correct direction. This can be achieved by looking for the other (the ball) at position (mover.hspeed*mover.hdir,mover.vspeed*mover.vdir). If this position is empty, the ball is moved there.
•	Thirdly, we want to avoid that the mover runs too fast. To this end, whenever a keyboard event is treated we set keypressed = 0 in a little piece of code.
•	Finally, there is the undo button. Very important for this game but not completely trivial to create. The idea is as follows. Each object and the mover have to remember their previous position. For this a little piece of code is used of the form {oldx = x; oldy = y;}. This is executed when the objects are created, and when a push occurs it is executed for the mover and for all balls. When the undo button is pressed (a mouse event) both for the mover and the objects the x and y positions are set to oldx and oldy . The undo button only appears when there is something to undo (at a push) and removes itself after you press it.