Nie wiem do końca czy o to mi chodzi o serializacje. Jakby wiem, że to bardzo zła praktyka i powinienem to napisać tablicowo-obiektowo, ale na ten moment mam taki kod:
function Level1() {
for (i = 1; i <= 36; i++) {
defaultSettings();
div.classList.add("level1");
board.style.width = "558px";
board.style.height = "248px";
}
}
function Level2() {
for (i = 1; i <= 78; i++) {
defaultSettings();
div.classList.add("level2");
board.style.width = "545.9px";
board.style.height = "252px";
}
}
function Level3() {
for (i = 1; i <= 189; i++) {
defaultSettings();
div.classList.add("level3");
board.style.width = "594px";
board.style.height = "154px";
}
}
function defaultSettings() {
div = document.createElement("div");
board = document.getElementById("board");
div.id = "pix" + i;
board.appendChild(div);
board.childNodes[i].addEventListener("click", function (e) {
target = e.target.id;
t = document.getElementById(target);
if (t.classList.contains("yellow")) {
t.classList.remove("yellow");
t.classList.add("red");
} else if (t.classList.contains("red")) {
t.classList.remove("red");
t.classList.add("destroyed");
destroyed = 1;
$(document).ready(function () {
$.ajax({
type: "POST",
url: 'includes/game2.inc.php',
data: {destroyed: destroyed, target: target},
success: function(data) {
if (data == "Error") {
alert("Ejj haker majster nie CITUJ :)");
}
alert(data);
},
error: function (xhr, status, error) {
alert(xhr + " " + status + " " + error);
},
});
});
} else if (t.classList.contains("destroyed")) {
alert("ID: " + target + " zostało już zniszczone");
} else {
t.classList.add("yellow");
}
});
}