From eb410782c0ea8520e88de6c28759800a2f8cb1f7 Mon Sep 17 00:00:00 2001 From: Aviortheking <2bazert@gmail.com> Date: Mon, 5 Feb 2018 11:19:44 +0100 Subject: [PATCH] correction & tweaks --- index.html | 25 +++++++++++++++++-------- prgm.js | 50 ++++++++++++++++++++++---------------------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index c4f8680..8a0558a 100644 --- a/index.html +++ b/index.html @@ -14,14 +14,19 @@ .black { background: black; } + .hidden { + visibility: hidden; + }
+ +
- - + + \ No newline at end of file diff --git a/prgm.js b/prgm.js index 2a2862c..0c7045d 100644 --- a/prgm.js +++ b/prgm.js @@ -5,61 +5,55 @@ var Prgm = { this.Ant.element= elementName; }, init: function(element, width) { - width++; table = ""; for (t = 0; t < width; t++) { - table += ''; + table += ""; for (i = 0; i < width; i++) { - table += ''; + table += ''; } table += ""; } - element.innerHTML += table; + element.innerHTML = table; }, - - Ant: { element: "table", prepos: [0,0], pos: [0,0], setAt: function(line, col) { - //console.log("Entering : Ant.setAt"); col--; line--; - document.getElementById(this.element).childNodes[0].childNodes[line].childNodes[col].classList.add("ant"); - this.pos = [line, col]; - this.prepos = [line+1, col]; + //window.alert(col + ", " + line + ", " + AntElement); + document.getElementById(this.element).childNodes[0].childNodes[col].childNodes[line].classList.add("ant"); + pos = document.getElementsByClassName("ant")[0]; + this.pos = [pos.getAttribute("line"), pos.getAttribute("col")]; + this.prepos = this.pos; + this.prepos[0] = this.pos[0] - 1; }, move: function() { - //console.log("Entering : Ant.move"); - //console.log("prepos : " + this.prepos + "\npos : " + this.pos); - //console.log("Diff : "+(parseInt(this.prepos[0])-parseInt(this.pos[0]))+", "+(parseInt(this.prepos[1])-parseInt(this.pos[1]))); - if(document.getElementsByClassName("ant")[0].classList.contains("black")) { - document.getElementsByClassName("ant")[0].classList.remove("black"); - //console.log("Black tile !\nSending : " + (parseInt(this.prepos[1])-parseInt(this.pos[1]))+", "+ (-(parseInt(this.prepos[0])-parseInt(this.pos[0])))); - this.a(parseInt(this.prepos[1])-parseInt(this.pos[1]), -(parseInt(this.prepos[0])-parseInt(this.pos[0]))); + window.alert(parseInt(this.prepos[0])+parseInt(this.pos[0])+", "+(parseInt(this.prepos[1])+parseInt(this.pos[1]))); + if(pos.classList.contains("black")) { + //window.alert(this.prepos[0]+this.pos[0]+", "+this.prepos[1]+this.pos[1]); + //window.alert(this.prepos); + this.a(); } else { - document.getElementsByClassName("ant")[0].classList.add("black"); - //console.log("White tile !\nSending : " + (-(parseInt(this.prepos[1])-parseInt(this.pos[1])))+", "+ (parseInt(this.prepos[0])-parseInt(this.pos[0]))); - this.a(-(parseInt(this.prepos[1])-parseInt(this.pos[1])), parseInt(this.prepos[0])-parseInt(this.pos[0])); + //window.alert(parseInt(this.prepos[0])+parseInt(this.pos[0])+", "+(parseInt(this.prepos[1])+parseInt(this.pos[1]))); + //window.alert(this.prepos); } + //window.alert(this.pos); }, a: function(line, col) { - //console.log("Entering : Ant.a"); - document.getElementsByClassName("ant")[0].classList.remove("ant"); - //console.log("Setting Ant Position to :\nLine : " + (line+parseInt(this.pos[0])) + "\nColumn : " + (col+parseInt(this.pos[1])) ); + //window.alert(line+", "+col); + //window.alert((line+parseInt(this.pos[0]))+", "+(col+parseInt(this.pos[1]))); + pos = document.getElementsByClassName("ant")[0].classList.remove("ant"); document .getElementById(this.element) .childNodes[0] - .childNodes[line+parseInt(this.pos[0])] - .childNodes[col+parseInt(this.pos[1])] + .childNodes[line-1+parseInt(this.prepos[0])] + .childNodes[col-1+parseInt(this.prepos[1])] .classList .add("ant"); this.prepos = this.pos; - this.pos = [line+parseInt(this.prepos[0]), col+parseInt(this.prepos[1])]; }, - - } } \ No newline at end of file