From 1a6d916f85ef7c7d4c01d1c5bbe64b08417a8a56 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Mon, 7 Sep 2020 21:02:37 -0500 Subject: [PATCH] Add ShipType enum and isShipCell helper to utils (#2) --- src/module/util.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/module/util.js b/src/module/util.js index 487e788..e618f95 100644 --- a/src/module/util.js +++ b/src/module/util.js @@ -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