Home Reference Source
import {Board} from './js/board.js'
public class | source

Board

Implements:

Board class, which stores the game board and all related methods

Constructor Summary

Public Constructor
public

constructor(numMines: number, rows: number, columns: number)

Constructor creates a board, setting all necessary variables and creating a 2D array to store the tiles based on user input.

Member Summary

Public Members
public

arr: Tile[]

2D array storing all tile objects on the board.

public

Number of columns (length) on the board.

public

Flag that indicates if the player has lost the game.

public

Number of mines that the user has flagged.

public

Variable to keep track of mines left that haven't been flagged.

public

Number of mines on the board.

public

Variable to keep track of tiles without a mine in it.

public

Variable to keep track of number of flags.

public

Number of rows (height) on the board.

public

Flag that indicates if the player has won the game.

Method Summary

Public Methods
public

This is a recursive function that will execute any one of block on the block been clicked.

public

getTileAdj(row: number, column: number): boolean

Finds the number of mines adjacent to the checked tile.

public

Checks the revealed status of a tile on the game board specified by the coordinates.

public

This function change each tile's adjNum. POSTCONDITION: All tiles that aren't mines have their adjacent number set to the number of mines adjacent to that tile on the game board.

public

This function plant the Mines inside the arr.

public

setFlag(row: number, column: number): boolean | null

This function changes one tile's flagged status, changes the number of flags and sets winner to true if all flags have been placed on all mines. PRECONDITION: The tile is revealed. POSTCONDITION: The tile clicked on either has a flag or doesn't, numFlags increments or decrements, minesNotFlagged increments or decrements (if a mine was the tile clicked on) and if the conditions are met for winning the game, set winner to true.

public

When the status of the game is Win or Lose, call this function to reveal all the blocks.

Public Constructors

public constructor(numMines: number, rows: number, columns: number) source

Constructor creates a board, setting all necessary variables and creating a 2D array to store the tiles based on user input. PRECONDITION: rows, columns, and numMines are within the correct ranges POSTCONDITION: arr is now populated with tiles; rows, columns, minesTotal, winner, loser, minesNotFlagged, numFlags, noMineTiles, all have set values.

Params:

NameTypeAttributeDescription
numMines number

Number of mines on the board.

rows number

Number of rows (height) on the board.

columns number

Number of columns (length) on the board.

Public Members

public arr: Tile[] source

2D array storing all tile objects on the board.

public columns: number source

Number of columns (length) on the board. Range: 2-45

public loser: boolean source

Flag that indicates if the player has lost the game.

public minesFlagged: number source

Number of mines that the user has flagged. Must be equal to minesTotal to win the game.

public minesNotFlagged: number source

Variable to keep track of mines left that haven't been flagged.

public minesTotal: number source

Number of mines on the board. Range: 1-2024 (Depending on board size)

public noMineTiles: number source

Variable to keep track of tiles without a mine in it.

public numFlags: number source

Variable to keep track of number of flags.

public rows: number source

Number of rows (height) on the board. Range: 2-45

public winner: boolean source

Flag that indicates if the player has won the game.

Public Methods

public clickReveal(i: number, j: number) source

This is a recursive function that will execute any one of block on the block been clicked. It will change all the tile's revealed = true, who have number 0. Even the tile set with flagged. POSTCONDITION: If a mine was clicked, set loser to true. If a number not 0 was clicked, set just that tile to be revealed. If a 0 was clicked, every adjacent tile not a mine is revealed. All spaces that were flagged that are now revealed are not flagged anymore.

Params:

NameTypeAttributeDescription
i number

Row property of tile being revealed.

j number

Column property of tile being revealed.

public getTileAdj(row: number, column: number): boolean source

Finds the number of mines adjacent to the checked tile.

Params:

NameTypeAttributeDescription
row number

Row coordinate for checked tile.

column number

Column coordinate for checked tile.

Return:

boolean

Mines adjacent to the tile being checked.

public isTileRevealed(row: number, column: number): boolean source

Checks the revealed status of a tile on the game board specified by the coordinates.

Params:

NameTypeAttributeDescription
row number

Row coordinate for checked tile.

column number

Column coordinate for checked tile.

Return:

boolean

Revealed status of the tile being checked.

public plantAdjNum() source

This function change each tile's adjNum. POSTCONDITION: All tiles that aren't mines have their adjacent number set to the number of mines adjacent to that tile on the game board.

public plantMine() source

This function plant the Mines inside the arr. The Number of Mines are given by player. Using Math.random() to ramdomly plant the Mines. POSTCONDITION: A number of random tiles specified by minesTotal are now set to be mines.

public setFlag(row: number, column: number): boolean | null source

This function changes one tile's flagged status, changes the number of flags and sets winner to true if all flags have been placed on all mines. PRECONDITION: The tile is revealed. POSTCONDITION: The tile clicked on either has a flag or doesn't, numFlags increments or decrements, minesNotFlagged increments or decrements (if a mine was the tile clicked on) and if the conditions are met for winning the game, set winner to true.

Params:

NameTypeAttributeDescription
row number

Row of tile being flagged.

column number

Column of tile being flagged.

Return:

boolean | null

The status of the tile - true for flagged, false for not flagged, null if nothing can be done

public showAllMine() source

When the status of the game is Win or Lose, call this function to reveal all the blocks. POSTCONDITION: Every tile is set to be revealed.