mirror of
https://github.com/Aviortheking/Langton-s-Ant.git
synced 2025-07-03 22:19:18 +00:00
Update prgm.js
This commit is contained in:
45
prgm.js
45
prgm.js
@ -1,8 +1,11 @@
|
|||||||
var AntElement = "table-0";
|
|
||||||
|
|
||||||
var Prgm = {
|
var Prgm = {
|
||||||
|
element: "table",
|
||||||
|
setElement: function(elementName) {
|
||||||
|
this.element = elementName;
|
||||||
|
this.Ant.element= elementName;
|
||||||
|
},
|
||||||
init: function(element, width) {
|
init: function(element, width) {
|
||||||
table = "<table id="+AntElement+">";
|
table = "<table id="+this.element+">";
|
||||||
for (t = 0; t < width; t++) {
|
for (t = 0; t < width; t++) {
|
||||||
table += "<tr>";
|
table += "<tr>";
|
||||||
for (i = 0; i < width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
@ -13,35 +16,43 @@ var Prgm = {
|
|||||||
element.innerHTML += table;
|
element.innerHTML += table;
|
||||||
},
|
},
|
||||||
Ant: {
|
Ant: {
|
||||||
|
element: "table",
|
||||||
prepos: [0,0],
|
prepos: [0,0],
|
||||||
pos: [0,0],
|
pos: [0,0],
|
||||||
setAt: function(line, col) {
|
setAt: function(line, col) {
|
||||||
col--;
|
col--;
|
||||||
line--;
|
line--;
|
||||||
//window.alert(col + ", " + line + ", " + AntElement);
|
//window.alert(col + ", " + line + ", " + AntElement);
|
||||||
document.getElementById(AntElement).childNodes[0].childNodes[col].childNodes[line].classList.add("ant");
|
document.getElementById(this.element).childNodes[0].childNodes[col].childNodes[line].classList.add("ant");
|
||||||
|
|
||||||
},
|
|
||||||
move: function() {
|
|
||||||
pos = document.getElementsByClassName("ant")[0];
|
pos = document.getElementsByClassName("ant")[0];
|
||||||
this.pos = [pos.getAttribute("line"), pos.getAttribute("col")];
|
this.pos = [pos.getAttribute("line"), pos.getAttribute("col")];
|
||||||
if(this.prepos[0] == 0 && this.prepos[1] == 0) {
|
this.prepos = this.pos;
|
||||||
this.force(1, 0);
|
this.prepos[0] = this.pos[0] - 1;
|
||||||
} else if(pos.classList.contains("black")) {
|
},
|
||||||
window.alert(this.prepos[0]+this.pos[0]+", "+this.prepos[1]+this.pos[1]);
|
move: function() {
|
||||||
window.alert(this.prepos);
|
|
||||||
//this.force();
|
|
||||||
} else {
|
|
||||||
window.alert(parseInt(this.prepos[0])+parseInt(this.pos[0])+", "+(parseInt(this.prepos[1])+parseInt(this.pos[1])));
|
window.alert(parseInt(this.prepos[0])+parseInt(this.pos[0])+", "+(parseInt(this.prepos[1])+parseInt(this.pos[1])));
|
||||||
window.alert(this.prepos);
|
|
||||||
|
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 {
|
||||||
|
//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);
|
//window.alert(this.pos);
|
||||||
},
|
},
|
||||||
force: function(line, col) {
|
a: function(line, col) {
|
||||||
//window.alert(line+", "+col);
|
//window.alert(line+", "+col);
|
||||||
//window.alert((line+parseInt(this.pos[0]))+", "+(col+parseInt(this.pos[1])));
|
//window.alert((line+parseInt(this.pos[0]))+", "+(col+parseInt(this.pos[1])));
|
||||||
pos = document.getElementsByClassName("ant")[0].classList.remove("ant");
|
pos = document.getElementsByClassName("ant")[0].classList.remove("ant");
|
||||||
document.getElementById(AntElement).childNodes[0].childNodes[line+parseInt(this.pos[0])].childNodes[col+parseInt(this.pos[1])].classList.add("ant");
|
document
|
||||||
|
.getElementById(this.element)
|
||||||
|
.childNodes[0]
|
||||||
|
.childNodes[line-1+parseInt(this.prepos[0])]
|
||||||
|
.childNodes[col-1+parseInt(this.prepos[1])]
|
||||||
|
.classList
|
||||||
|
.add("ant");
|
||||||
this.prepos = this.pos;
|
this.prepos = this.pos;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user