From 78bebead107be235e37ac0434cd6e2ab3be45e14 Mon Sep 17 00:00:00 2001 From: BRNSystems <70092437+BRNSystems@users.noreply.github.com> Date: Sun, 16 Jan 2022 13:56:53 +0100 Subject: [PATCH] add auxiliaries --- index.css | 33 ++++++++++++++++-------- index.html | 19 ++++++++------ index.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 100 insertions(+), 25 deletions(-) diff --git a/index.css b/index.css index 7b22ab3..d273674 100644 --- a/index.css +++ b/index.css @@ -13,19 +13,27 @@ td{ height: 100%; padding: 0.4%; } -#playfield, -#bg { +#playfield { width: 100%; height: 100%; } #localdiv, #remotediv { - width: 100%; - height: 100%; + width: 70%; + height: 70%; float: center; padding-top: 1%; padding-bottom: 1%; } +#localauxdiv, +#remoteauxdiv { + width: 25%; + height: 25%; + float: center; + padding-top: 1%; + padding-bottom: 1%; + padding-left: 1%; +} #local, #remote { width: 100%; @@ -33,14 +41,17 @@ td{ table-layout: fixed; object-fit: contain; } +#localaux, +#remoteaux { + width: 100%; + height: 100%; + table-layout: fixed; + object-fit: contain; +} #playfield { display: flex; - flex-direction: column; + flex-wrap: wrap; } -#bg { - background-color: #000000; - position: absolute; - top: 0; - left: 0; - z-index: -100; +body{ + background-color: black; } \ No newline at end of file diff --git a/index.html b/index.html index 364e45c..d2510db 100644 --- a/index.html +++ b/index.html @@ -10,17 +10,22 @@ Battleship -
-
-
-
+
+
-
-
+
+
+ +
+
+
-
+
+
+ +
diff --git a/index.js b/index.js index 9f95a77..3d94484 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,14 @@ //my personal variables let w = 10; let h = 10; -let x = "✔"; -let o = "⬤"; let lgrid = new Array(w); let rgrid = new Array(w); +let waux = 10; +let haux = 10; +let x = "✔"; +let o = "⬤"; +let lauxgrid = new Array(w); +let rauxgrid = new Array(w); //Write arrays to html function writegrid() { for (let i = 0; i < w; i++) { @@ -14,8 +18,16 @@ function writegrid() { } } } +function writeauxgrid(){ + for (let i = 0; i < waux; i++) { + for (let j = 0; j < haux; j++) { + $('#lac' + i + '-' + j).html(lauxgrid[i][j]); + $('#rac' + i + '-' + j).html(rauxgrid[i][j]); + } + } +} -$(function () { +function inittable(){ for (let i = 0; i < w; i++) { //create columns $('#local').append(''); @@ -33,11 +45,32 @@ $(function () { } } +} + +function initauxtable(){ + for (let i = 0; i < waux; i++) { + //create columns + $('#localaux').append(''); + $('#remoteaux').append(''); + for (let j = 0; j < haux; j++) { + //create cells + $('#lax' + i).append(''); + $('#rax' + i).append(''); + //add divs to cells + $('#lacx' + i + '-' + j).append('
'); + $('#racx' + i + '-' + j).append('
'); + //add arrays to grids + lauxgrid[i] = new Array(haux); + rauxgrid[i] = new Array(haux); + } + } +} + +function randomizetable(){ for (let i = 0; i < w; i++) { for (let j = 0; j < h; j++) { - //randomly choose between o and x - let rand = Math.floor(Math.random() * 2); - if (rand == 0) { + let r = Math.floor(Math.random() * 2); + if (r == 0) { lgrid[i][j] = x; rgrid[i][j] = o; } else { @@ -46,6 +79,32 @@ $(function () { } } } - //sync grid +} + +function randomizeaux(){ + for (let i = 0; i < waux; i++) { + for (let j = 0; j < haux; j++) { + let r = Math.floor(Math.random() * 2); + if (r == 0) { + lauxgrid[i][j] = x; + rauxgrid[i][j] = o; + } else { + lauxgrid[i][j] = o; + rauxgrid[i][j] = x; + } + } + } +} + +function main() { + inittable(); + initauxtable(); + randomizetable(); writegrid(); + randomizeaux(); + writeauxgrid(); +} + +$(function () { + main(); }); \ No newline at end of file