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

0.0.2 • Public • Published

Minesweeper Game Logic

A small package including the minesweeper game logic. The minesweeper game is a fantastic exercise to learn a new Frontend framework, such as Vue, React, Svelte or Angular.

Installation

Using yarn:

yarn add minesweeper-logic

or npm:

npm i minesweeper-logic

Usage

Use the makeGameBoard function to generate a size by size game board with size randomly placed mines:

import { makeGameBoard } from 'minesweeper-logic'
 
const gameBoard = makeGameBoard(10)

The game board is a bidimensional array where each element represents a cell:

type BoardCell = {
  row: number
  col: number
  key: string
  hasMine: boolean
  minesAroundCount: number
  isHidden: boolean
}

When a cell needs to be uncovered, use the updateBoard function. This function returns a new updated board together with some game stats:

type UpdatedBoardResult = {
  readonly board: GameBoard
  readonly isGameOver: boolean
  readonly isGameWon: boolean
}

In your code:

import { updateBoard } from 'minesweeper-logic'
 
const { isGameOver, isGameWon, board } = updateBoard(board).unhidingCell(2, 4)

Readme

Keywords

none

Package Sidebar

Install

npm i minesweeper-logic

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

6.32 kB

Total Files

11

Last publish

Collaborators

  • angelsolaorbaiceta