0.1.0 • Published 4 years ago
sweepengine v0.1.0
sweepengine
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 sweepengineInitialization
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
bombstotal number of bombsflagsnumber of flagged fieldscellsmatrix with cells. Each cell consists ofcolcolumn indexrowrow indexvaluenumber of adjacent minesisFlaggedflag indicatorisRevealedrevealed indicatorisBombbomb indicatorisZeroempty field indicator
gameStateobject containing following propertiescodestate value fromGameSateenumdetailsoptional 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
0.1.0
4 years ago