Function
Static Public Summary | ||
public |
boardGen() Run when start/restart button is pressed, generates a game board if input conditions are met. |
|
public |
Run when length input and height field are changed, enables and disables the number of mines input field based on validity of length and height input field. |
|
public |
Run when any tile in the game table is clicked, reveals the tile clicked on. |
|
public |
rightClick(clicked: Object): null Run when any tile in the game table is right-clicked, places or removes a flag on the tile clicked. |
Static Public
public boardGen() source
import {boardGen} from './js/main.js'
Run when start/restart button is pressed, generates a game board if input conditions are met. Checks the validitiy of every input field (non-empty and within their respective ranges). If they are all valid, a new Board object is created and stored in game. The Board then plants the mines and all adjacent numbers calling plantMine and plantAdjNum. The game board area is then cleared and a table is created by creating element nodes of type TD, attaching a numeric ID to each one. These are then appended into TR nodes, which are then appended to the TABLE node in index.html. The status display is then unhidden and the start button is changed to a reset button. If all input fields are not valid, display an alert and force the user to try their inputs again. PRECONDITION: startButton has been clicked by the user and boardLength, boardHeight, and minesInput are valid inputs. POSTCONDITION: game is now a Board with mines and adjacent numbers planted, game is represented as a table, startButton is now red and reads Restart, and flags/mines stat bar is now shown.
public checkMinesInput() source
import {checkMinesInput} from './js/main.js'
Run when length input and height field are changed, enables and disables the number of mines input field based on validity of length and height input field. Checks length and height input fields and checks whether they are valid or not. If they are both valid (non-empty and within the range 2-45), the input field for the number of mines is set to non-read only and the maximum value is set to be equal to the area of the board - 1. If not, the input field for the number of mines is set to read only. PRECONDITION: boardLength and boardHeight have been changed by the user and both are valid inputs. POSTCONDITION: minesInput's readOnly attribute has been set to true or false.
public leftClick(clicked: Object): null source
import {leftClick} from './js/main.js'
Run when any tile in the game table is clicked, reveals the tile clicked on. Checks if tile clicked on is unrevealed and if the game is still happening. If not, return null. If so, run clickreveal on the tile, determining its coordinates from the tile's ID. If the tile is a mine, run showAllMine, display all mines on the board and show the game over display. If the tile is a number not equal to 0, show the number on the clicked tile. If the tile is equal to 0, loop through the whole board looking for revealed tiles and display all revealed tiles. PRECONDITION: A tile on the game board has been left-clicked by the user, the game is still running, the tile clicked on has not yet been revealed POSTCONDITION: The tile clicked on has been revealed, as well as any adjacent tiles if the tile clicked on is a 0
Params:
Name | Type | Attribute | Description |
clicked | Object | The TD object that was clicked, gotten from event.target |
public rightClick(clicked: Object): null source
import {rightClick} from './js/main.js'
Run when any tile in the game table is right-clicked, places or removes a flag on the tile clicked. Checks if if the game is still happening. If not, return null. If so, determine coordinates of the tile clicked using its ID and execute flagTile. If flagTile returns true, change the space inside the tile to be a flag. If flagTile returns false, remove the flag inside the tile. If flagTile returns null, return null. Then check if the game was won (all flags placed on all mines). If so, show the winner display. PRECONDITION: A tile on the game board has been right-clicked by the user, the game is still running, the tile clicked on has not yet been revealed POSTCONDITION: The tile clicked on has been flagged if not already, the flag is removed if it was already flagged.
Params:
Name | Type | Attribute | Description |
clicked | Object | The TD object that was clicked, gotten from event.target |