1.1.2 • Published 4 years ago

notillew-minefield-core v1.1.2

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Notillew Minefield Core (minesweeper)

A javascript minefield generator

coverage build passing contributions types

Installation

yarn add notillew-minefield-core

or

npm install notillew-minefield-core

Documentation

This minefield generator exports a minefield array and a object with mines mapping You can use minesMap to validate if a position is mine.

Minefields

const { minefields } = minefield.generate(12, 12, 12);
// Output Array[number[]]
// [
//  [2, -1,  3, 1],
//  [2, -1, -1, 1]
// ]

Minesmap

const { minesMap } = minefield.generate(12, 12, 12);
// Output Object { 'index': Array[number] }
// { 
//  '0', [1], 
//  '1': [1, 2]
// }

Properties Generate(columns, rows, mines)

NameRequiredMinMaxType
columnstrue12-int
rowstrue12-int
minestrue6less than columns * rowsint

React example usage

import React from 'react';
import { FaBomb } from 'react-icons/fa';

import minefield from 'notillew-minefield-core';
import './App.css';

function App() {
  const { minefields } = minefield.generate(12, 12, 12);

  const getClassName = (number) => {
    switch (number) {
      case -1:
        
        return 'mine';

      case 0: 
        return 'empty'
    
      default:
        return 'number';
    }
  }
  return (
    <div className="App">
      <ul className="minefields">
        {minefields.map(rows => (
          <li className="row">
            {rows.map(col => (
              <div 
                className={`col-${getClassName(col)}`}
              >
                {col === -1 ? <FaBomb color="black" /> : col}
              </div>
            ))}
          </li>
        ))}
      </ul>
    </div>
  );
}

export default App;
1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago