new Board(rows, cols, numShip)
Represents a single player's board, storing the status of each space and ship as a 2-D array of Space objects.
Parameters:
Name | Type | Description |
---|---|---|
rows |
number | The number of rows the board will have |
cols |
number | The number of columns the board will have |
numShip |
number | Number of ships in the current board |
Methods
checkWin()
Determines whether the game has been won on this board
Returns:
If all ship spaces on this board have been sunk
isIntersecting()
Returns:
Whether the given row, col coordinates intersect the ship
placeShip(length, row, col, isVertical)
Creates a new Ship object and updates this.ships and this.spaces accordingly
Parameters:
Name | Type | Description |
---|---|---|
length |
number | How many spaces long the ship should be |
row |
number | The row coordinate of the top end of the ship |
col |
number | The col coordinate of the left end of the ship |
isVertical |
boolean | Direction of ship (false = horizontal) |
render(table, game, isCurrentPlayer, preventClicking)
Render the current state of the board to an HTML table element, optionally showing ships and allowing clicking
Parameters:
Name | Type | Description |
---|---|---|
table |
HTMLTableElement | The table to render the board to |
game |
Gameplay | to use the clickSpace method of |
isCurrentPlayer |
boolean | for whether all ship locations should be visible |
preventClicking |
boolean | to restrict a player to click again |