Initial commit

This commit is contained in:
Florian Bouillon 2018-02-01 00:30:17 +01:00
commit 7cdd4ea107
2 changed files with 74 additions and 0 deletions

26
index.html Normal file
View File

@ -0,0 +1,26 @@
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="resource://activity-stream/css/activity-stream.css">
<style>
table, th, td {
border: 1px solid black;
padding: 15px;
}
.ant {
background: red;
}
</style>
<script type="text/javascript" src="prgm.js"></script>
</head>
<body>
<div class="prgm">
</div>
</body>
<script>
prgm = Prgm;
AntElement = "test";
prgm.init(document.getElementsByClassName("prgm")[0], 10);
prgm.Ant.setAt(1,2);
</script>
</html>

48
prgm.js Normal file
View File

@ -0,0 +1,48 @@
var AntElement = "table-0";
var Prgm = {
init: function(element, width) {
table = "<table id="+AntElement+">";
for (t = 0; t < width; t++) {
table += "<tr>";
for (i = 0; i < width; i++) {
table += '<td col="'+t+'" line="'+i+'"></td>';
}
table += "</tr>";
}
element.innerHTML += table;
},
Ant: {
prepos: [0,0],
pos: [0,0],
setAt: function(line, col) {
col--;
line--;
//window.alert(col + ", " + line + ", " + AntElement);
document.getElementById(AntElement).childNodes[0].childNodes[col].childNodes[line].classList.add("ant");
},
move: function() {
pos = document.getElementsByClassName("ant")[0];
this.pos = [pos.getAttribute("line"), pos.getAttribute("col")];
if(this.prepos[0] == 0 && this.prepos[1] == 0) {
this.force(1, 0);
} else if(pos.classList.contains("black")) {
window.alert(this.prepos[0]+this.pos[0]+", "+this.prepos[1]+this.pos[1]);
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(this.prepos);
}
//window.alert(this.pos);
},
force: function(line, col) {
//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(AntElement).childNodes[0].childNodes[line+parseInt(this.pos[0])].childNodes[col+parseInt(this.pos[1])].classList.add("ant");
this.prepos = this.pos;
},
}
}