Tizenotodik vizsga

This commit is contained in:
2024-12-12 22:09:15 +01:00
parent 79e178286b
commit 58ce6bef18

View File

@ -1,3 +1,5 @@
var rules = [[1, 2], [1, -2], [-1, 2], [-1, -2], [-2, 1], [-2, -1], [2, 1], [2, -1]]
document.addEventListener("DOMContentLoaded", () => {
var blocks = Array.from(document.getElementsByClassName("c"));
var matrix = [];
@ -13,14 +15,22 @@ document.addEventListener("DOMContentLoaded", ()=>{
for (var j = 0; j < matrix[i].length; j++) {
matrix[i][j].addEventListener("click", (function (ci, cj) {
return function () {
try{
var flag = true;
if(matrix[ci +1][cj+2].children.length == 0) flag = false;
if(matrix[ci -1][cj-2].children.length == 0) flag = false;
if(matrix[ci +2][cj+1].children.length == 0) flag = false;
if(matrix[ci -2][cj-1].children.length == 0) flag = false;
console.log(flag)
}catch{}
var newloc = [];
for (var j = 0; j < rules.length; j++) {
try {
if (matrix[ci + rules[j][0]][cj + rules[j][1]].children.length != 0) {
flag = false;
newloc = [ci + rules[j][0], cj + rules[j][1]];
}
}
catch { }
}
if (!flag) {
var paci = matrix[newloc[0]][newloc[1]].children[0].cloneNode(true);
matrix[newloc[0]][newloc[1]].children[0].remove();
this.appendChild(paci);
}
}
})(i, j));
}