Javascript Sokoban game script

I’ve always been addicted to logic games and Sokoban is one of them.

From Wikipedia: Sokoban (warehouse keeper) is a transport puzzle in which the player pushes boxes around a maze, viewed from above, and tries to put them in designated locations. Only one box may be pushed at a time, not two, and boxes cannot be pulled. As the puzzle would be extremely difficult to create physically, it is usually implemented as a video game.

In some cases Javascript is not the ideal language to code puzzle games, because the player can read the code and have a clue about the puzzle. Just imagine a Minesweeper game in Javascript… a brief look at the code and you’ll know where the bombs are.

In Sokoban, reading the code is useless because you don’t play in a static level, but level changes as you move your player pushing blocks.

At this time the script is very essential, and contains just one level, but I am going to push (yes, talking about sokoban, I obviously “push”) the script very far away, including level editors, leagues and even more.

Every single line of the script will be explained, as usual, meanwhile you can watch the code from your browser.

Can you solve the level? Can you tell me where did I rip the main sprite?

  • Wow, truly amazing! Would be nice for a ‘reload level’ button, since I absolutely suck at it, lol.

    Always interesting how JavaScript can actually make some cool games. The only other cool script I’ve seen really though, is one for a JavaScript-based Battleship, complete with an A.I. that never tries the same spot twice, and can continuously try to attack around a spot if it hits a ship.

    Real cool stuff, keep it up!

  • galaxy

    hard!! i did it in 35 moves :).

  • Emanuele Feronato

    The game can be solved in 33 moves…

    • Gabriel

      Hey, Emanuele Feronato

      The game can actually bem solved ein 31 steps, i did ;)

      • Emanuele Feronato


  • galaxy

    yes i pushed the boxes in the wrong oder.
    i got it now.
    did you make that level? its a nice level anyway.
    what has happen here? why is the main text on the left side now? it makes some pages with AS on them move the boarder to the right.

  • great game cant wait to see how its done!

  • Kayn

    It’s Marle, from Chrono Trigger methinks… :)
    Nice puzzle though – you’re right, some puzzles lend themselves well to formats like this. They’re mainly of the type where all the information you need is already viewable on the screen and no amount of source reading can help you.

  • I guess a minesweeper would be possible using Javascript without letting the user see the solution in the source.

    It would be an interesting project ..

    Nice sokoban, by the way.

  • actually 31 ;)
    these graphics totally remind me of a project I made where I ripped the blocks from the original nes mario for a 2d adventure dos game =D

    And this puzzle game reminds me of solomon’s key.

  • OK. I give up. Where did you rip the main sprite? Amazing JS, by the way!

  • Pingback: A “very old” Flash Sokoban prototype : Emanuele Feronato - italian geek and PROgrammer()

  • Pingback: Trying to solve a Sokoban level with brute force : Emanuele Feronato()

  • Pingback: GameJS and gameQuery: two javascript libraries for game developers : Emanuele Feronato()