Skip to content

WillTDA/Sokoban-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 Sokoban Engine 📦

Create and manage Sokoban games with ease.

NPM

Downloads Discord Server

Features

  • 🔓 Fully Customisable | The size of the Sokoban grid, number of boxes, and entity appearances is up to you.

  • 🎮 Randomly Generated Levels | Generate a random game with a random size and number of boxes. (Custom levels coming soon!)

  • 🏗️ Easy to Set Up and Use | All the logic that goes into making Sokoban is handled for you.

  • ⏱️ Synchronous | All functions are synchronous, so you can use them in your game loop.

Please Note: Custom levels are not currently supported. Want to request a feature? Open an Issue, or Fork and Submit a Pull Request on our GitHub Repository!

Installation and Setup

To install the package, run the following command in your terminal:

npm i sokoban-engine --save

Setting up the package for use is as simple as creating a new Sokoban class and setting the width and height of the game grid.

There are also a few other options you can set, such as the number of boxes on the level, and the appearance of each entity.

const SokobanEngine = require("sokoban-engine");
const sokoban = new SokobanEngine(10, 10, { // Setting up a 10x10 grid
    boxes: 2, // Number of boxes to generate on the level
    entityAppearance: { // Customise what each entity on the level looks like
        player: "🤪",
        box: "📦",
        boxOnGoal: "✅",
        goal: "📥",
        wall: "🚧",
        floor: "⬛"
    }
});

Code Example

Here's a quick example of how to use the package to create your own Sokoban game to run in the terminal.

const SokobanEngine = require("sokoban-engine");
const sokoban = new SokobanEngine(10, 10);

while (!sokoban.hasWon) { // Keep running the game until all boxes are on the goals

    // Displaying the level
    console.clear();
    console.log(`Sokoban`);
    console.log(`Moves: ${sokoban.moves.toLocaleString()}`);
    sokoban.level.forEach(row => console.log(row.join("")));
    console.log("(w,a,s,d) to move, (r) to restart the level, (q) to quit");

    let movement = // Get the user's input somehow

    switch (movement) {
        case "w":
            sokoban.moveUp(); // Move up
            break;
        case "a":
            sokoban.moveLeft(); // Move left
            break;
        case "s":
            sokoban.moveDown(); // Move down
            break;
        case "d":
            sokoban.moveRight(); // Move right
            break;
        case 'r':
            sokoban.reset(); // Restart the level
            break;
        case "q":
            process.exit(); // Quit the game
    }
}

// Displaying the level
console.clear();
console.log(`Sokoban`);
console.log(`Moves: ${sokoban.moves.toLocaleString()}`);
sokoban.level.forEach(row => console.log(row.join("")));
console.log("You win!");

Contact Us

About

Create and manage Sokoban games with ease.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published