0.1.0 • Published 3 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 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 bombsflags
number of flagged fieldscells
matrix with cells. Each cell consists ofcol
column indexrow
row indexvalue
number of adjacent minesisFlagged
flag indicatorisRevealed
revealed indicatorisBomb
bomb indicatorisZero
empty field indicator
gameState
object containing following propertiescode
state value fromGameSate
enumdetails
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
0.1.0
3 years ago