Socket
Socket
Sign inDemoInstall

sokoban-engine

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sokoban-engine

Create and manage Sokoban games. Levels and entities are fully customisable.


Version published
Weekly downloads
4
increased by100%
Maintainers
1
Install size
656 kB
Created
Weekly downloads
 

Readme

Source

📦 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

Keywords

FAQs

Last updated on 20 Mar 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc