Add ShipType enum and isShipCell helper to utils (#2)

issue-2
Garrett Mills 4 years ago
parent 6d5050fa79
commit 1a6d916f85
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -22,6 +22,19 @@ export const GridCellState = {
Missed: 'missed',
}
/**
* Returns true if the given grid cell state represents a ship in some way.
* @param {GridCellState} grid_cell_state
* @return {boolean}
*/
export function isShipCell(grid_cell_state) {
return [
GridCellState.Ship,
GridCellState.Damaged,
GridCellState.Sunk,
].includes(grid_cell_state)
}
/**
* Enum of all possible players.
* @type {object}
@ -52,6 +65,22 @@ export const GameState = {
PlayerVictory: 'player_victory',
}
/**
* The various supported ship types, by dimension.
* @type {object}
*/
export const ShipType = {
x1: '1x1',
x2: '1x2',
x3: '1x3',
x4: '1x4',
x5: '1x5',
}
export function isShipType(type) {
return ['1x1', '1x2', '1x3', '1x4', '1x5'].includes(type)
}
/**
* Makes a deep copy of the value passed in.
* @param {*} obj

Loading…
Cancel
Save