1.0.1 â€Ē Published 2 years ago

sokoban-engine v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

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