diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2023-02-28 15:44:44 +0100 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2023-04-13 14:29:47 +0200 |
| commit | f1c31316a12a76c9b9af4b40e605eb040d7dbd43 (patch) | |
| tree | 6019979099dba38e83de865462a19c2943156743 /battleshipFiles/Battleship.js | |
| download | battleship-f1c31316a12a76c9b9af4b40e605eb040d7dbd43.tar.gz battleship-f1c31316a12a76c9b9af4b40e605eb040d7dbd43.tar.zst battleship-f1c31316a12a76c9b9af4b40e605eb040d7dbd43.zip | |
v1.0.0
Diffstat (limited to 'battleshipFiles/Battleship.js')
| -rw-r--r-- | battleshipFiles/Battleship.js | 36 |
1 files changed, 36 insertions, 0 deletions
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 |
