sweepengine
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

sweepengine

Node.js CI

Handy and easy to use game engine for Minesweeper UI clients. This package is framework independent so it's up to you which UI technology would like to use.

How to

Installation

npm install sweepengine

Initialization

Just import the required functionality

import { generate, nextState, ActionType, GameState } from 'sweepengine'

Usage

Generate a new board state

let state = generate({
  rows: 5,
  cols: 5,
  bombs: 5
});

Build a new state after some user interaction

state = nextState(state, selectedCell, ActionType.Primary);

State contains following fields

  • bombs total number of bombs
  • flags number of flagged fields
  • cells matrix with cells. Each cell consists of
    • col column index
    • row row index
    • value number of adjacent mines
    • isFlagged flag indicator
    • isRevealed revealed indicator
    • isBomb bomb indicator
    • isZero empty field indicator
  • gameState object containing following properties
    • code state value from GameSate enum
    • details optional state details (eg. failure cell indices in case of game over)

Play

Example game loop:

let state = generate({ rows, cols, bombs});

while (
  state.gameState.code !== GameState.GameOver &&
  state.gameState.code !== GameState.Completed
) {
  renderUi(state); // your custom function

  let { activeCell, actionType } = waitForUserInteraction(state); // your custom function

  state = nextState(state, activeCell, actionType);
}

License

The code is free and open-source under the MIT license, so feel free to use it in any way you like.

Author

Readme

Keywords

Package Sidebar

Install

npm i sweepengine

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

19.2 kB

Total Files

15

Last publish

Collaborators

  • kozubikmichal