Skip to content

Minesweeper game logic. Great for implementing the game and learn a new frontend framework.

License

Notifications You must be signed in to change notification settings

angelsolaorbaiceta/minesweeper-logic

Repository files navigation

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)

About

Minesweeper game logic. Great for implementing the game and learn a new frontend framework.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published