# bombsweeper.js

> A JavaScript module that implements state management for a Minesweeper style game.

Latest version **1.0.1** (published 2017-09-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install bombsweeper.js
pnpm add bombsweeper.js
yarn add bombsweeper.js
bun add bombsweeper.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-09-01 |
| First published | 2017-08-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Andrew Berry |
| Maintainers | andrewberry |
| Keywords | javascript, minesweeper-style-game |

## Links

- npm: https://www.npmjs.com/package/bombsweeper.js
- Repository: https://github.com/AndrewBerry/bombsweeper.js
- Issues: https://github.com/AndrewBerry/bombsweeper.js/issues
- npm.io page: https://npm.io/package/bombsweeper.js

## Recent versions

- 1.0.1 (latest) — 2017-09-01
- 1.0.0 — 2017-08-30

## README

# bombsweeper.js
[![Build Status](https://travis-ci.org/AndrewBerry/bombsweeper.js.svg?branch=master)](https://travis-ci.org/AndrewBerry/bombsweeper.js)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/91c5182568ee4c2a902ae85fc014cc83)](https://www.codacy.com/app/AndrewBerry/bombsweeper.js?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=AndrewBerry/bombsweeper.js&amp;utm_campaign=Badge_Grade)

A JavaScript module that implements state management for a Minesweeper style bombsweeper.

## Installation
```bash
npm install --save bombsweeper.js
```

## Usage
```js
import BombSweeper from 'bombsweeper.js';

const bombsweeper = new BombSweeper(8, 8); // create a bombsweeper board at 8x8

bombsweeper.onWin = () => { alert('Win!'); }; // callback invoked on win
bombsweeper.onLoss = () => { alert('Lose!'); }; // callback invoked on loss

bombsweeper.PlaceBombs(10); // places 10 bombs randomly

// rendering game based on the following:
bombsweeper.board;
bombsweeper.mask;

// ...
bombsweeper.CheckCell(0, 0); // user clicked cell at 0, 0
// ...
```

## Methods
You can interact with the bombsweeper state after creation:
```js
const bombsweeper = new BombSweeper(width, height);
```

### .PlaceBomb(x, y)
Places a bomb at the specified (`x`, `y`) coordinates and increments any non-bomb adjacent cells. You most likely won't be using this method as .PlaceBombs(count) is a better fit for most use cases.

```js
const bombsweeper = new BombSweeper(5, 5);
bombsweeper.PlaceBomb(1,1);

/*
    0 0 0 0 0
    0 1 1 1 0
    0 1 * 1 0
    0 1 1 1 0
    0 0 0 0 0
*/
```

### .PlaceBombs(count)
This will randomly place `count` bombs on the bombsweeper board, utilising the .PlaceBomb(x, y) method mentioned above.

```js
const bombsweeper = new BombSweeper(5, 5);
bombsweeper.PlaceBombs(4);

/*
    * * 1 0 0
    2 3 2 1 0
    0 1 * 1 0
    0 1 1 2 1
    0 0 0 1 *
*/
```

If the count supplied is greater than the area of the board, .PlaceBombs() will run until the board has been filled. 

### .CheckCell(x, y)
This method is used to chip through the mask, flood filling if a zero cell is selected and checking win/loss all in one.

```js
const bombsweeper = new BombSweeper(5, 5);
bombsweeper.PlaceBombs(4);

/*
    Board:      Mask:
    * * 1 0 0   F F F F F
    2 3 2 1 0   F F F F F
    0 1 * 1 0   F F F F F
    0 1 1 2 1   F F F F F
    0 0 0 1 *   F F F F F
*/

bombsweeper.CheckCell(3, 0); // flood fill

/*
    Board:      Mask:
    * * 1 0 0   F F F T T
    2 3 2 1 0   F F F F T
    0 1 * 1 0   F F F F T
    0 1 1 2 1   F F F F F
    0 0 0 1 *   F F F F F
*/

bombsweeper.CheckCell(1, 1); // numeric cell > 0

/*
    Board:      Mask:
    * * 1 0 0   F F F T T
    2 3 2 1 0   F T F F T
    0 1 * 1 0   F F F F T
    0 1 1 2 1   F F F F F
    0 0 0 1 *   F F F F F
*/
```

---
_Source: https://npm.io/package/bombsweeper.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
