0.0.4 • Published 5 years ago

@jonathanbuchner/minesweeper v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Minesweeper

This project assists creating a minesweeper javascript game. The purpose of this project was assisting a friend by creating an npm package that she consumed to create a minesweeper game.

Getting Started

Download

npm i @jonathanbuchner/minesweeper

Include minesweeper class in JavaScript (Example)

import { Minesweeper } from '../node_modules/@jonathanbuchner/minesweeper/dist/minsweeper';

Available Methods

let width; //Width of board.
let height; //Height of board.
let mines; //Mines in board.

//Constructor
new Minesweeper(width: number, height: number, mines: number);

//Square
class Square{
    id: number; //Position of mine.
    isMine: boolean; //True if mine.
    number: number | null; //is null if square contains mine, otherwise contains the number of surround mines.
    isVisible: boolean;  //Used to track if mine has been.
}

//Methods
game.getBoard();  //returns all squares as an array.

game.getSquare(id: number): Square //returns square based on id.

game.checkIsMine(id: number): boolean //returns if square is mine.

game.getNumber(id: number): number | null //returns squares number.  returns null if mine.

game.getIsVisible(id: number): boolean //returns if square is visible.

game.markVisible(id: number): void //marks a square as visible.

game.HasWon(): boolean //Returns true if all non mines are visible squares.  

game.HasLost(): boolean //Returns true if a mine is a visible. 

Recommended Approach 1. Make a new game 2. Use .getboard() to get all the squares. Only show numbers to squares if the square is marked as visible. 3. When a user clicks a square, 1) Mark the square as visible. .markVisible() 2) Display the updated board. .getBoard() 3) Check if the user has lost the game (a visible square that is a mine will return true). .hasLost() 4) Check if the user has won the game (all squares that are not mines are visible). .hasWon()

Authors

Jonathan Buchner - jonathanbuchner.com

License

This project is licensed under the MIT License - see the LICENSE.md file for details