UNPKG

game-battleship

Version:
111 lines (79 loc) 3.29 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: shipArea.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: shipArea.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * This entity is representing the player's battle area * * @class Area * @constructor * @param {string} type - This defines the type of the ship "P" &amp; "Q" * @param {Array} dimension - Represnts the dimension of the area * @param {Array} ships - Represnts the ships for a player */ class Area { constructor({dimension, ships}) { this.parsedDimensions_ = dimension; this.shipYard = new Array(this.parsedDimensions_[0]); for (let shipX = 0; shipX &lt; this.parsedDimensions_[0]; shipX++) { this.shipYard[shipX] = new Array(this.parsedDimensions_[1]); } this.totalShipCount_ = 0; for (let shipCount = 0; shipCount &lt; ships.length; shipCount++) { for (let shipDimX = 0; shipDimX &lt; ships[shipCount].dimension[0]; shipDimX++) { for (let shipDimY = 0; shipDimY &lt; ships[shipCount].dimension[1]; shipDimY++) { const shipLocation = this.shipYard[(ships[shipCount].coordinates[0] - 1) + shipDimX][(ships[shipCount].coordinates[1] - 1) + shipDimY]; if (shipLocation) { throw new Error("Bad Config: Overlapping ships"); } this.shipYard[(ships[shipCount].coordinates[0] - 1) + shipDimX][(ships[shipCount].coordinates[1] - 1) + shipDimY] = Object.assign(Object.create(Object.getPrototypeOf(ships[shipCount])), ships[shipCount]); this.totalShipCount_ = this.totalShipCount_ + 1; } } } } /** * Function to check if the area is destroyed * @returns {Boolean} returns true if area is destroyed else false */ isAreaDestroyed() { return !this.totalShipCount_; } /** * Function to decremen the ship count * @returns {null} returns nothing */ decrementShipCount() { this.totalShipCount_--; } } module.exports = Area; </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Area.html">Area</a></li><li><a href="Player.html">Player</a></li><li><a href="Ship.html">Ship</a></li></ul><h3>Global</h3><ul><li><a href="global.html#battle">battle</a></li><li><a href="global.html#fileReader">fileReader</a></li><li><a href="global.html#parseCoordinates">parseCoordinates</a></li><li><a href="global.html#validateArgs">validateArgs</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 19 2019 14:14:50 GMT+0530 (India Standard Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>