new Gameplay(rows, cols, numShips)
Manages the boards and user interaction during gameplay (ship placement and attacking)
Parameters:
Name | Type | Description |
---|---|---|
rows |
number | The number of rows the boards have |
cols |
number | The number of columns the boards have |
numShips |
number | The number of ships each player has |
- Source:
Methods
blankBoards()
Render the boards, hides the ships on both boards, for use during turn switching
- Source:
clickSpace(cell, isCurrentPlayer)
Handles a space being clicked on either board
Parameters:
Name | Type | Description |
---|---|---|
cell |
Space | The Space object that was clicked |
isCurrentPlayer |
boolean | Whether the board that was clicked belongs to the player whose turn it currently is |
- Source:
gameEnd()
Render the boards, showing ships on both boards, and display a victory message
- Source:
msg()
Display a message to the current player
- Source:
newShip(cell)
Places a new ship on the current player's board
Parameters:
Name | Type | Description |
---|---|---|
cell |
Space | The space the user clicked on, which will be the top/left end of the new ship |
- Source:
playerName(player) → {string}
Parameters:
Name | Type | Description |
---|---|---|
player |
boolean | Which player to get the name of |
- Source:
Returns:
The name of the specified player
- Type
- string
renderBoards()
Render the boards, only showing ships on the current player's board
- Source:
switchTurns()
Sets up the next player's turn by hiding the turn switch modal and displaying their ships
- Source: