From f1c31316a12a76c9b9af4b40e605eb040d7dbd43 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 28 Feb 2023 15:44:44 +0100 Subject: v1.0.0 --- battleshipFiles/Battleship.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 battleshipFiles/Battleship.js (limited to 'battleshipFiles/Battleship.js') diff --git a/battleshipFiles/Battleship.js b/battleshipFiles/Battleship.js new file mode 100644 index 0000000..9b2a62a --- /dev/null +++ b/battleshipFiles/Battleship.js @@ -0,0 +1,36 @@ +class Battleship +{ + constructor(name) + { + // Set name + this.name = name; + // Initializing game map + this.gameMap = createGameMap(); + // Declaring how many of which type ships there would be + this.shipsMap = new Map(); + this.shipsMap.set(4, NUM_OF_4); + this.shipsMap.set(3, NUM_OF_3); + this.shipsMap.set(2, NUM_OF_2); + this.shipsMap.set(1, NUM_OF_1); + this.shipsArray = []; + for(let [key, value] of this.shipsMap) + for(let i = 0; i < value; i++) + this.shipsArray.push(key); + + this.howManyShips = eval(this.shipsArray.join('+')); + // creating vars, used later + this.destroyedShips = 0; + } +} +function createGameMap() +{ + let gameMap = new Array(MAP_SIZE + 2); + for(let i = 0; i < MAP_SIZE + 2; i++) + gameMap[i] = new Array(MAP_SIZE + 2); + + for(let i = 0; i < MAP_SIZE + 2; i++) + for(let j = 0; j < MAP_SIZE + 2; j++) + gameMap[i][j] = 0; + + return gameMap; +} \ No newline at end of file -- cgit v1.3.1