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 |
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 |
clickReveal(i: number, j: number) 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 |
isTileRevealed(row: number, column: number): boolean 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 |
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.
Public Members
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 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.
public getTileAdj(row: number, column: number): boolean source
Finds the number of mines adjacent to the checked tile.
public isTileRevealed(row: number, column: number): boolean source
Checks the revealed status of a tile on the game board specified by the coordinates.
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.
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.