Javascript Sokoban 30 lines

Hello everyone, I decided to join the general madness. Almost everything they could have written in 30 lines, but I did not find the good old sokoban (maybe I searched badly), so I want to fill this gap.



Link to fiddle

If someone is not up to date, the point is to push the boxes to the indicated places. Boxes can only be pushed, not pulled. You can push only one box in front of you at a time. The walls of the labyrinth are painted black, the boxes are blue, the places for the boxes are gray, the boxes in the right places are red, the player is green. Control the arrow keys.

The level map is set in the levelData array at the beginning of the script.
Symbols used:
  • 'w' - wall
  • 'b' - box
  • 's' or space - free space
  • 'y' - player

Also popular now: