/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Box class 5 (renamed to Asker) var Asker = Container.expand(function () { var self = Container.call(this); var boxAsset = self.attachAsset('tapBox5', { anchorX: 0.5, anchorY: 0.5 }); self.boxAsset = boxAsset; self.tapCount = 0; self.counterTxt = new Text2('0', { size: 90, fill: 0x000000 }); self.counterTxt.anchor.set(0, 0); self.counterTxt.x = -self.boxAsset.width / 2 + 8; self.counterTxt.y = -self.boxAsset.height / 2 + 8; self.addChild(self.counterTxt); self.down = function (x, y, obj) { tween.stop(self.boxAsset, { scaleX: true, scaleY: true }); self.boxAsset.scaleX = 1.0; self.boxAsset.scaleY = 1.0; tween(self.boxAsset, { scaleX: 1.2, scaleY: 1.2 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(self.boxAsset, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); // Find Et and Odun boxes in tapBoxes var etBox = null; var odunBox = null; for (var i = 0; i < tapBoxes.length; i++) { if (tapBoxes[i] && tapBoxes[i].constructor === Et) { etBox = tapBoxes[i]; } if (tapBoxes[i] && tapBoxes[i].constructor === Odun) { odunBox = tapBoxes[i]; } } // Only allow decrement if requirements are met if (etBox && odunBox && etBox.tapCount >= 20 && odunBox.tapCount >= 10) { etBox.tapCount -= 20; odunBox.tapCount -= 10; if (etBox.tapCount < 0) { etBox.tapCount = 0; } if (odunBox.tapCount < 0) { odunBox.tapCount = 0; } etBox.counterTxt.setText(etBox.tapCount); odunBox.counterTxt.setText(odunBox.tapCount); self.tapCount += 1; self.counterTxt.setText(self.tapCount); } }; return self; }); // Box class 3 (renamed to Et) var Et = Container.expand(function () { var self = Container.call(this); var boxAsset = self.attachAsset('tapBox3', { anchorX: 0.5, anchorY: 0.5 }); self.boxAsset = boxAsset; self.tapCount = 0; self.counterTxt = new Text2('0', { size: 90, fill: 0x222222 }); self.counterTxt.anchor.set(0, 0); self.counterTxt.x = -self.boxAsset.width / 2 + 8; self.counterTxt.y = -self.boxAsset.height / 2 + 8; self.addChild(self.counterTxt); self.down = function (x, y, obj) { tween.stop(self.boxAsset, { scaleX: true, scaleY: true }); self.boxAsset.scaleX = 1.0; self.boxAsset.scaleY = 1.0; tween(self.boxAsset, { scaleX: 1.2, scaleY: 1.2 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(self.boxAsset, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); self.tapCount += 1; self.counterTxt.setText(self.tapCount); }; return self; }); // Box class 1 (renamed to Odun) var Odun = Container.expand(function () { var self = Container.call(this); var boxAsset = self.attachAsset('odun', { anchorX: 0.5, anchorY: 0.5 }); self.boxAsset = boxAsset; self.tapCount = 0; self.counterTxt = new Text2('0', { size: 90, fill: 0x222222 }); self.counterTxt.anchor.set(0, 0); self.counterTxt.x = -self.boxAsset.width / 2 + 8; self.counterTxt.y = -self.boxAsset.height / 2 + 8; self.addChild(self.counterTxt); self.down = function (x, y, obj) { tween.stop(self.boxAsset, { scaleX: true, scaleY: true }); self.boxAsset.scaleX = 1.0; self.boxAsset.scaleY = 1.0; tween(self.boxAsset, { scaleX: 1.2, scaleY: 1.2 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(self.boxAsset, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); self.tapCount += 1; self.counterTxt.setText(self.tapCount); }; return self; }); // Box class 6 (renamed to Silah) var Silah = Container.expand(function () { var self = Container.call(this); var boxAsset = self.attachAsset('tapBox6', { anchorX: 0.5, anchorY: 0.5 }); self.boxAsset = boxAsset; self.tapCount = 0; self.counterTxt = new Text2('0', { size: 90, fill: 0x222222 }); self.counterTxt.anchor.set(0, 0); self.counterTxt.x = -self.boxAsset.width / 2 + 8; self.counterTxt.y = -self.boxAsset.height / 2 + 8; self.addChild(self.counterTxt); self.down = function (x, y, obj) { tween.stop(self.boxAsset, { scaleX: true, scaleY: true }); self.boxAsset.scaleX = 1.0; self.boxAsset.scaleY = 1.0; tween(self.boxAsset, { scaleX: 1.2, scaleY: 1.2 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(self.boxAsset, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); // Find Odun and Tas boxes in tapBoxes var odunBox = null; var tasBox = null; for (var i = 0; i < tapBoxes.length; i++) { if (tapBoxes[i] && tapBoxes[i].constructor === Odun) { odunBox = tapBoxes[i]; } if (tapBoxes[i] && tapBoxes[i].constructor === Tas) { tasBox = tapBoxes[i]; } } // Only allow decrement if requirements are met if (odunBox && tasBox && odunBox.tapCount >= 20 && tasBox.tapCount >= 10) { odunBox.tapCount -= 20; tasBox.tapCount -= 10; if (odunBox.tapCount < 0) { odunBox.tapCount = 0; } if (tasBox.tapCount < 0) { tasBox.tapCount = 0; } odunBox.counterTxt.setText(odunBox.tapCount); tasBox.counterTxt.setText(tasBox.tapCount); self.tapCount += 1; self.counterTxt.setText(self.tapCount); } }; return self; }); // Box class 2 (renamed to Tas) var Tas = Container.expand(function () { var self = Container.call(this); var boxAsset = self.attachAsset('tas', { anchorX: 0.5, anchorY: 0.5 }); self.boxAsset = boxAsset; self.tapCount = 0; self.counterTxt = new Text2('0', { size: 90, fill: 0x222222 }); self.counterTxt.anchor.set(0, 0); self.counterTxt.x = -self.boxAsset.width / 2 + 8; self.counterTxt.y = -self.boxAsset.height / 2 + 8; self.addChild(self.counterTxt); self.down = function (x, y, obj) { tween.stop(self.boxAsset, { scaleX: true, scaleY: true }); self.boxAsset.scaleX = 1.0; self.boxAsset.scaleY = 1.0; tween(self.boxAsset, { scaleX: 1.2, scaleY: 1.2 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(self.boxAsset, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); self.tapCount += 1; self.counterTxt.setText(self.tapCount); }; return self; }); // Box class 4 (renamed to ev) var ev = Container.expand(function () { var self = Container.call(this); var boxAsset = self.attachAsset('ev', { anchorX: 0.5, anchorY: 0.5 }); self.boxAsset = boxAsset; self.tapCount = 0; self.counterTxt = new Text2('0', { size: 90, fill: 0x222222 }); self.counterTxt.anchor.set(0, 0); self.counterTxt.x = -self.boxAsset.width / 2 + 8; self.counterTxt.y = -self.boxAsset.height / 2 + 8; self.addChild(self.counterTxt); self.down = function (x, y, obj) { tween.stop(self.boxAsset, { scaleX: true, scaleY: true }); self.boxAsset.scaleX = 1.0; self.boxAsset.scaleY = 1.0; tween(self.boxAsset, { scaleX: 1.2, scaleY: 1.2 }, { duration: 80, easing: tween.easeOut, onFinish: function onFinish() { tween(self.boxAsset, { scaleX: 1.0, scaleY: 1.0 }, { duration: 100, easing: tween.easeIn }); } }); // Find Tas and Odun boxes in tapBoxes var tasBox = null; var odunBox = null; for (var i = 0; i < tapBoxes.length; i++) { if (tapBoxes[i] && tapBoxes[i].constructor === Tas) { tasBox = tapBoxes[i]; } if (tapBoxes[i] && tapBoxes[i].constructor === Odun) { odunBox = tapBoxes[i]; } } // Only allow decrement if requirements are met if (tasBox && odunBox && tasBox.tapCount >= 20 && odunBox.tapCount >= 10) { tasBox.tapCount -= 20; odunBox.tapCount -= 10; if (tasBox.tapCount < 0) { tasBox.tapCount = 0; } if (odunBox.tapCount < 0) { odunBox.tapCount = 0; } tasBox.counterTxt.setText(tasBox.tapCount); odunBox.counterTxt.setText(odunBox.tapCount); self.tapCount += 1; self.counterTxt.setText(self.tapCount); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Box colors for variety // No global score display needed; each box is fully independent var boxColors = [0xff5252, // red 0x40c4ff, // blue 0x69f0ae, // green 0xffd740, // yellow 0xb388ff, // purple 0xff80ab // pink ]; // Register box asset (all boxes use same size, color is set per instance) // Layout: 2 rows x 3 columns, centered var boxSize = 340; var hGap = 120; var vGap = 160; var cols = 3; var rows = 2; var totalWidth = cols * boxSize + (cols - 1) * hGap; var totalHeight = rows * boxSize + (rows - 1) * vGap; var startX = (2048 - totalWidth) / 2 + boxSize / 2; var startY = (2732 - totalHeight) / 2 + boxSize / 2; // Store all boxes for possible future use var tapBoxes = []; var boxClasses = [Odun, Tas, Et, ev, Asker, Silah]; var boxIdx = 0; // Load saved tapCounts if available (sync) var savedTapCounts = storage.tapBoxCounts; if (!Array.isArray(savedTapCounts)) { savedTapCounts = [0, 0, 0, 0, 0, 0]; } // After loading, initialize boxes var boxIdx = 0; for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { var idx = row * cols + col; var BoxClass = boxClasses[boxIdx]; var box = new BoxClass(); // Align Odun a little further down and a little further to the right from the top left, others as before if (BoxClass === Odun) { box.x = boxSize / 2 + 280; // 280px to the right (moved a little further right) box.y = boxSize / 2 + 200; // 200px down (unchanged) box.boxAsset.color = 0xff5252; // red } else if (BoxClass === Tas) { // Place Tas (stone) box immediately to the right of Odun (wood) box box.x = boxSize / 2 + 280 + boxSize + hGap; // right next to Odun box.y = boxSize / 2 + 200; // same vertical as Odun box.boxAsset.color = boxColors[idx % boxColors.length]; } else if (BoxClass === Et) { // Place Et box immediately to the right of Tas box box.x = boxSize / 2 + 280 + 2 * (boxSize + hGap); // right next to Tas box.y = boxSize / 2 + 200; // same vertical as Odun and Tas box.boxAsset.color = boxColors[idx % boxColors.length]; } else if (BoxClass === ev) { // Align ev under Odun box.x = boxSize / 2 + 280; // same x as Odun box.y = boxSize / 2 + 200 + boxSize + vGap; // one row below Odun box.boxAsset.color = boxColors[idx % boxColors.length]; } else if (BoxClass === Asker) { // Align Asker under Tas box.x = boxSize / 2 + 280 + boxSize + hGap; // same x as Tas box.y = boxSize / 2 + 200 + boxSize + vGap; // one row below Tas box.boxAsset.color = boxColors[idx % boxColors.length]; } else if (BoxClass === Silah) { // Align Silah under Et box.x = boxSize / 2 + 280 + 2 * (boxSize + hGap); // same x as Et box.y = boxSize / 2 + 200 + boxSize + vGap; // one row below Et box.boxAsset.color = boxColors[idx % boxColors.length]; } else { box.x = startX + col * (boxSize + hGap); box.y = startY + row * (boxSize + vGap); box.boxAsset.color = boxColors[idx % boxColors.length]; } game.addChild(box); tapBoxes.push(box); // Restore tapCount if available if (typeof savedTapCounts[boxIdx] === "number" && savedTapCounts[boxIdx] > 0) { box.tapCount = savedTapCounts[boxIdx]; if (box.counterTxt) { box.counterTxt.setText(box.tapCount); } } boxIdx++; } } // Save tapCounts on every change function saveTapBoxCounts() { var counts = []; for (var i = 0; i < tapBoxes.length; i++) { counts.push(tapBoxes[i].tapCount || 0); } storage.set('tapBoxCounts', counts); } // Patch all box classes to call saveTapBoxCounts after tapCount changes var _oldDowns = []; for (var i = 0; i < boxClasses.length; i++) { (function (idx) { var Cls = boxClasses[idx]; var proto = Cls.prototype; if (proto && typeof proto.down === "function") { if (!_oldDowns[idx]) { _oldDowns[idx] = proto.down; } proto.down = function (x, y, obj) { _oldDowns[idx].apply(this, arguments); saveTapBoxCounts(); }; } })(i); } // No dragging or move logic needed; all interaction is per-box // No update loop needed for this minimal game // No timer/game over logic for MVP // End of file
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
// Box class 5 (renamed to Asker)
var Asker = Container.expand(function () {
var self = Container.call(this);
var boxAsset = self.attachAsset('tapBox5', {
anchorX: 0.5,
anchorY: 0.5
});
self.boxAsset = boxAsset;
self.tapCount = 0;
self.counterTxt = new Text2('0', {
size: 90,
fill: 0x000000
});
self.counterTxt.anchor.set(0, 0);
self.counterTxt.x = -self.boxAsset.width / 2 + 8;
self.counterTxt.y = -self.boxAsset.height / 2 + 8;
self.addChild(self.counterTxt);
self.down = function (x, y, obj) {
tween.stop(self.boxAsset, {
scaleX: true,
scaleY: true
});
self.boxAsset.scaleX = 1.0;
self.boxAsset.scaleY = 1.0;
tween(self.boxAsset, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.boxAsset, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Find Et and Odun boxes in tapBoxes
var etBox = null;
var odunBox = null;
for (var i = 0; i < tapBoxes.length; i++) {
if (tapBoxes[i] && tapBoxes[i].constructor === Et) {
etBox = tapBoxes[i];
}
if (tapBoxes[i] && tapBoxes[i].constructor === Odun) {
odunBox = tapBoxes[i];
}
}
// Only allow decrement if requirements are met
if (etBox && odunBox && etBox.tapCount >= 20 && odunBox.tapCount >= 10) {
etBox.tapCount -= 20;
odunBox.tapCount -= 10;
if (etBox.tapCount < 0) {
etBox.tapCount = 0;
}
if (odunBox.tapCount < 0) {
odunBox.tapCount = 0;
}
etBox.counterTxt.setText(etBox.tapCount);
odunBox.counterTxt.setText(odunBox.tapCount);
self.tapCount += 1;
self.counterTxt.setText(self.tapCount);
}
};
return self;
});
// Box class 3 (renamed to Et)
var Et = Container.expand(function () {
var self = Container.call(this);
var boxAsset = self.attachAsset('tapBox3', {
anchorX: 0.5,
anchorY: 0.5
});
self.boxAsset = boxAsset;
self.tapCount = 0;
self.counterTxt = new Text2('0', {
size: 90,
fill: 0x222222
});
self.counterTxt.anchor.set(0, 0);
self.counterTxt.x = -self.boxAsset.width / 2 + 8;
self.counterTxt.y = -self.boxAsset.height / 2 + 8;
self.addChild(self.counterTxt);
self.down = function (x, y, obj) {
tween.stop(self.boxAsset, {
scaleX: true,
scaleY: true
});
self.boxAsset.scaleX = 1.0;
self.boxAsset.scaleY = 1.0;
tween(self.boxAsset, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.boxAsset, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
self.tapCount += 1;
self.counterTxt.setText(self.tapCount);
};
return self;
});
// Box class 1 (renamed to Odun)
var Odun = Container.expand(function () {
var self = Container.call(this);
var boxAsset = self.attachAsset('odun', {
anchorX: 0.5,
anchorY: 0.5
});
self.boxAsset = boxAsset;
self.tapCount = 0;
self.counterTxt = new Text2('0', {
size: 90,
fill: 0x222222
});
self.counterTxt.anchor.set(0, 0);
self.counterTxt.x = -self.boxAsset.width / 2 + 8;
self.counterTxt.y = -self.boxAsset.height / 2 + 8;
self.addChild(self.counterTxt);
self.down = function (x, y, obj) {
tween.stop(self.boxAsset, {
scaleX: true,
scaleY: true
});
self.boxAsset.scaleX = 1.0;
self.boxAsset.scaleY = 1.0;
tween(self.boxAsset, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.boxAsset, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
self.tapCount += 1;
self.counterTxt.setText(self.tapCount);
};
return self;
});
// Box class 6 (renamed to Silah)
var Silah = Container.expand(function () {
var self = Container.call(this);
var boxAsset = self.attachAsset('tapBox6', {
anchorX: 0.5,
anchorY: 0.5
});
self.boxAsset = boxAsset;
self.tapCount = 0;
self.counterTxt = new Text2('0', {
size: 90,
fill: 0x222222
});
self.counterTxt.anchor.set(0, 0);
self.counterTxt.x = -self.boxAsset.width / 2 + 8;
self.counterTxt.y = -self.boxAsset.height / 2 + 8;
self.addChild(self.counterTxt);
self.down = function (x, y, obj) {
tween.stop(self.boxAsset, {
scaleX: true,
scaleY: true
});
self.boxAsset.scaleX = 1.0;
self.boxAsset.scaleY = 1.0;
tween(self.boxAsset, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.boxAsset, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Find Odun and Tas boxes in tapBoxes
var odunBox = null;
var tasBox = null;
for (var i = 0; i < tapBoxes.length; i++) {
if (tapBoxes[i] && tapBoxes[i].constructor === Odun) {
odunBox = tapBoxes[i];
}
if (tapBoxes[i] && tapBoxes[i].constructor === Tas) {
tasBox = tapBoxes[i];
}
}
// Only allow decrement if requirements are met
if (odunBox && tasBox && odunBox.tapCount >= 20 && tasBox.tapCount >= 10) {
odunBox.tapCount -= 20;
tasBox.tapCount -= 10;
if (odunBox.tapCount < 0) {
odunBox.tapCount = 0;
}
if (tasBox.tapCount < 0) {
tasBox.tapCount = 0;
}
odunBox.counterTxt.setText(odunBox.tapCount);
tasBox.counterTxt.setText(tasBox.tapCount);
self.tapCount += 1;
self.counterTxt.setText(self.tapCount);
}
};
return self;
});
// Box class 2 (renamed to Tas)
var Tas = Container.expand(function () {
var self = Container.call(this);
var boxAsset = self.attachAsset('tas', {
anchorX: 0.5,
anchorY: 0.5
});
self.boxAsset = boxAsset;
self.tapCount = 0;
self.counterTxt = new Text2('0', {
size: 90,
fill: 0x222222
});
self.counterTxt.anchor.set(0, 0);
self.counterTxt.x = -self.boxAsset.width / 2 + 8;
self.counterTxt.y = -self.boxAsset.height / 2 + 8;
self.addChild(self.counterTxt);
self.down = function (x, y, obj) {
tween.stop(self.boxAsset, {
scaleX: true,
scaleY: true
});
self.boxAsset.scaleX = 1.0;
self.boxAsset.scaleY = 1.0;
tween(self.boxAsset, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.boxAsset, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
self.tapCount += 1;
self.counterTxt.setText(self.tapCount);
};
return self;
});
// Box class 4 (renamed to ev)
var ev = Container.expand(function () {
var self = Container.call(this);
var boxAsset = self.attachAsset('ev', {
anchorX: 0.5,
anchorY: 0.5
});
self.boxAsset = boxAsset;
self.tapCount = 0;
self.counterTxt = new Text2('0', {
size: 90,
fill: 0x222222
});
self.counterTxt.anchor.set(0, 0);
self.counterTxt.x = -self.boxAsset.width / 2 + 8;
self.counterTxt.y = -self.boxAsset.height / 2 + 8;
self.addChild(self.counterTxt);
self.down = function (x, y, obj) {
tween.stop(self.boxAsset, {
scaleX: true,
scaleY: true
});
self.boxAsset.scaleX = 1.0;
self.boxAsset.scaleY = 1.0;
tween(self.boxAsset, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 80,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.boxAsset, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
// Find Tas and Odun boxes in tapBoxes
var tasBox = null;
var odunBox = null;
for (var i = 0; i < tapBoxes.length; i++) {
if (tapBoxes[i] && tapBoxes[i].constructor === Tas) {
tasBox = tapBoxes[i];
}
if (tapBoxes[i] && tapBoxes[i].constructor === Odun) {
odunBox = tapBoxes[i];
}
}
// Only allow decrement if requirements are met
if (tasBox && odunBox && tasBox.tapCount >= 20 && odunBox.tapCount >= 10) {
tasBox.tapCount -= 20;
odunBox.tapCount -= 10;
if (tasBox.tapCount < 0) {
tasBox.tapCount = 0;
}
if (odunBox.tapCount < 0) {
odunBox.tapCount = 0;
}
tasBox.counterTxt.setText(tasBox.tapCount);
odunBox.counterTxt.setText(odunBox.tapCount);
self.tapCount += 1;
self.counterTxt.setText(self.tapCount);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Box colors for variety
// No global score display needed; each box is fully independent
var boxColors = [0xff5252,
// red
0x40c4ff,
// blue
0x69f0ae,
// green
0xffd740,
// yellow
0xb388ff,
// purple
0xff80ab // pink
];
// Register box asset (all boxes use same size, color is set per instance)
// Layout: 2 rows x 3 columns, centered
var boxSize = 340;
var hGap = 120;
var vGap = 160;
var cols = 3;
var rows = 2;
var totalWidth = cols * boxSize + (cols - 1) * hGap;
var totalHeight = rows * boxSize + (rows - 1) * vGap;
var startX = (2048 - totalWidth) / 2 + boxSize / 2;
var startY = (2732 - totalHeight) / 2 + boxSize / 2;
// Store all boxes for possible future use
var tapBoxes = [];
var boxClasses = [Odun, Tas, Et, ev, Asker, Silah];
var boxIdx = 0;
// Load saved tapCounts if available (sync)
var savedTapCounts = storage.tapBoxCounts;
if (!Array.isArray(savedTapCounts)) {
savedTapCounts = [0, 0, 0, 0, 0, 0];
}
// After loading, initialize boxes
var boxIdx = 0;
for (var row = 0; row < rows; row++) {
for (var col = 0; col < cols; col++) {
var idx = row * cols + col;
var BoxClass = boxClasses[boxIdx];
var box = new BoxClass();
// Align Odun a little further down and a little further to the right from the top left, others as before
if (BoxClass === Odun) {
box.x = boxSize / 2 + 280; // 280px to the right (moved a little further right)
box.y = boxSize / 2 + 200; // 200px down (unchanged)
box.boxAsset.color = 0xff5252; // red
} else if (BoxClass === Tas) {
// Place Tas (stone) box immediately to the right of Odun (wood) box
box.x = boxSize / 2 + 280 + boxSize + hGap; // right next to Odun
box.y = boxSize / 2 + 200; // same vertical as Odun
box.boxAsset.color = boxColors[idx % boxColors.length];
} else if (BoxClass === Et) {
// Place Et box immediately to the right of Tas box
box.x = boxSize / 2 + 280 + 2 * (boxSize + hGap); // right next to Tas
box.y = boxSize / 2 + 200; // same vertical as Odun and Tas
box.boxAsset.color = boxColors[idx % boxColors.length];
} else if (BoxClass === ev) {
// Align ev under Odun
box.x = boxSize / 2 + 280; // same x as Odun
box.y = boxSize / 2 + 200 + boxSize + vGap; // one row below Odun
box.boxAsset.color = boxColors[idx % boxColors.length];
} else if (BoxClass === Asker) {
// Align Asker under Tas
box.x = boxSize / 2 + 280 + boxSize + hGap; // same x as Tas
box.y = boxSize / 2 + 200 + boxSize + vGap; // one row below Tas
box.boxAsset.color = boxColors[idx % boxColors.length];
} else if (BoxClass === Silah) {
// Align Silah under Et
box.x = boxSize / 2 + 280 + 2 * (boxSize + hGap); // same x as Et
box.y = boxSize / 2 + 200 + boxSize + vGap; // one row below Et
box.boxAsset.color = boxColors[idx % boxColors.length];
} else {
box.x = startX + col * (boxSize + hGap);
box.y = startY + row * (boxSize + vGap);
box.boxAsset.color = boxColors[idx % boxColors.length];
}
game.addChild(box);
tapBoxes.push(box);
// Restore tapCount if available
if (typeof savedTapCounts[boxIdx] === "number" && savedTapCounts[boxIdx] > 0) {
box.tapCount = savedTapCounts[boxIdx];
if (box.counterTxt) {
box.counterTxt.setText(box.tapCount);
}
}
boxIdx++;
}
}
// Save tapCounts on every change
function saveTapBoxCounts() {
var counts = [];
for (var i = 0; i < tapBoxes.length; i++) {
counts.push(tapBoxes[i].tapCount || 0);
}
storage.set('tapBoxCounts', counts);
}
// Patch all box classes to call saveTapBoxCounts after tapCount changes
var _oldDowns = [];
for (var i = 0; i < boxClasses.length; i++) {
(function (idx) {
var Cls = boxClasses[idx];
var proto = Cls.prototype;
if (proto && typeof proto.down === "function") {
if (!_oldDowns[idx]) {
_oldDowns[idx] = proto.down;
}
proto.down = function (x, y, obj) {
_oldDowns[idx].apply(this, arguments);
saveTapBoxCounts();
};
}
})(i);
}
// No dragging or move logic needed; all interaction is per-box
// No update loop needed for this minimal game
// No timer/game over logic for MVP
// End of file