Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'boxspacing is not defined' in or related to this line: 'b.y = offset + startY + i * (boxSize + boxspacing); // determine this' Line Number: 448
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'cBox is not defined' in or related to this line: 'cBox.width = cBox.height = tileSize;' Line Number: 428
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (13 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'return n;' Line Number: 176
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'return n;' Line Number: 176
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'return n;' Line Number: 176
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'return n;' Line Number: 176
User prompt
Please fix the bug: 'Set is not a constructor' in or related to this line: 'return n;' Line Number: 176
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: cosole is not defined' in or related to this line: 'cosole.log('levelContainer:', levelContainer);' Line Number: 126
Code edit (1 edits merged)
Please save this source code
Code edit (19 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: tween is not defined' in or related to this line: 'tween(self, {' Line Number: 110 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Arrow is not defined' in or related to this line: 'var arrow = new Arrow();' Line Number: 40
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: visited.has is not a function' in or related to this line: '_iterator.f();' Line Number: 268
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: neighbours is not defined' in or related to this line: 'console.log(neighbours);' Line Number: 254
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
var Board = Container.expand(function () {
var self = Container.call(this);
self.boxGraphics = self.attachAsset('board', {
anchorX: 0.5,
anchorY: 0.5
});
self.paint = function () {
self.boxGraphics.width = boardSize;
self.boxGraphics.height = boardSize;
var startX = -self.width / 2;
var startY = -self.height / 2;
var boxSize = calculateTileSize();
var boxSpacing = boxSize * spacingRatio;
var offset = boxSize / 2 + boxSpacing;
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
var box = self.addChild(new Box());
box.width = box.height = boxSize;
box.x = offset + startX + i * (boxSize + boxSpacing);
box.y = offset + startY + j * (boxSize + boxSpacing);
box.setAlpha(0.075);
}
}
};
self.paint();
});
var Box = Container.expand(function () {
var self = Container.call(this);
var boxGraphics = self.attachAsset('box', {
anchorX: 0.5,
anchorY: 0.5
});
self.setAlpha = function (i) {
self.alpha = i;
};
});
var ColorBox = Container.expand(function (colorIndex) {
var self = Container.call(this);
self.colorIndex = colorIndex;
var boxGraphics = self.attachAsset('box', {
anchorX: 0.5,
anchorY: 0.5,
tint: colors[colorIndex]
});
self.gridX = 0;
self.gridY = 0;
self.speed = 10;
self.down = function (x, y, obj) {
//console.log(x, y, obj);
colorBoxClicked(self);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
function _slicedToArray(r, e) {
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) {
return;
}
f = !1;
} else {
for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) {
;
}
}
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) {
return;
}
} finally {
if (o) {
throw n;
}
}
}
return a;
}
}
function _arrayWithHoles(r) {
if (Array.isArray(r)) {
return r;
}
}
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
t && (r = t);
var _n = 0,
F = function F() {};
return {
s: F,
n: function n() {
return _n >= r.length ? {
done: !0
} : {
done: !1,
value: r[_n++]
};
},
e: function e(r) {
throw r;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o,
a = !0,
u = !1;
return {
s: function s() {
t = t.call(r);
},
n: function n() {
var r = t.next();
return a = r.done, r;
},
e: function e(r) {
u = !0, o = r;
},
f: function f() {
try {
a || null == t["return"] || t["return"]();
} finally {
if (u) {
throw o;
}
}
}
};
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) {
return _arrayLikeToArray(r, a);
}
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) {
n[e] = r[e];
}
return n;
}
var colors = ['0x000000', '0xffffff', '0xffff00'];
var gridSize = 5;
var spacingRatio = 0.2;
var boardSize = 1300;
function calculateTileSize() {
// Example of getting desired tileSize depending on gridSize (for different size grids)
// maintaining 1300px board size and 0.2 gutter between tiles.
var tileSize = boardSize / ((gridSize + 1) * spacingRatio + gridSize);
return tileSize;
console.log(tileSize);
}
var tileSize = calculateTileSize();
var board = new Board();
board.x = 1024;
board.y = 2732 / 2;
game.addChild(board);
var l1 = [[0, 0, 0, 0, 0], [0, 1, 1, 0, 0], [0, 1, 2, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]];
var l2 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]];
var levels = [l1, l2];
var currentLevel = levels[0].slice(0); //copy without reference, so we have original for retry/level reset.
var levelContainer = new Container();
levelContainer.x = 1024;
levelContainer.y = 2732 / 2;
game.addChild(levelContainer);
function paintLevel(a) {
var startX = -boardSize / 2;
var startY = -boardSize / 2;
var boxSize = tileSize;
var boxSpacing = boxSize * spacingRatio;
var offset = boxSize / 2 + boxSpacing;
for (var i = 0; i < a.length; i++) {
for (var j = 0; j < a[0].length; j++) {
if (a[j][i] != 0) {
var cBox = levelContainer.addChild(new ColorBox(a[j][i]));
cBox.width = cBox.height = boxSize;
cBox.x = offset + startX + i * (boxSize + boxSpacing);
cBox.y = offset + startY + j * (boxSize + boxSpacing);
cBox.gridX = i;
cBox.gridY = j;
}
}
}
}
paintLevel(currentLevel);
// Click handler
game.down = function (x, y, obj) {
//board.scale.x *= 1.2;
//board.scale.y *= 1.2;
//console.log(x, y, obj);
};
function findConnectedSameColorTiles(startBox) {
var connectedTiles = [];
var visited = [];
var queue = [startBox];
var targetColor = startBox.colorIndex;
while (queue.length > 0) {
var currentBox = queue.shift(); // Use pop() for DFS
var _currentBox = currentBox,
x = _currentBox.gridX; //x,
y = _currentBox.gridY; //y; // Assuming each box has x, y properties
if (visited.indexOf(currentBox) === -1) {
visited.push(currentBox);
connectedTiles.push(currentBox);
// Check all adjacent tiles
var neighbors = getAdjacentTiles(x, y);
console.log(neighbors);
var _iterator = _createForOfIteratorHelper(neighbors),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var neighbor = _step.value;
//if (neighbor.colorIndex === targetColor && !visited.has(neighbor)) {
if (neighbor === targetColor && !visited.has(neighbor)) {
queue.push(neighbor);
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
}
return connectedTiles;
}
function getAdjacentTiles(x, y) {
var adjacentTiles = [];
var directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]; // left, right, up, down
for (var _i = 0, _directions = directions; _i < _directions.length; _i++) {
var _directions$_i = _slicedToArray(_directions[_i], 2),
dx = _directions$_i[0],
dy = _directions$_i[1];
var newX = x + dx;
var newY = y + dy;
// Check if the new position is within the grid boundaries
if (newX >= 0 && newX < currentLevel.length && newY >= 0 && newY < currentLevel[0].length) {
var colorBox = levelContainer.children.find(function (child) {
return child.gridX === newX && child.gridY === newY;
});
if (colorBox) {
adjacentTiles.push(colorBox);
}
}
}
return adjacentTiles;
}
function colorBoxClicked(b) {
console.log('colorbox clicked:', b);
// Find connected tiles with same color
var t = findConnectedSameColorTiles(b);
console.log(t);
for (var i = 0; i < t.length; i++) {
t[i].destroy();
}
}
A large calm background drawing for a puzzle game, in dark calm blueish colors and non-confusing content. High definition. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A quadratic polished dark blue marble slate. Front perspective with right angles. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A white question mark in a circle, like for a help button in a game.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A white X in a circle, like for a close window button in a game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A white questionmark on a black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A green check mark on a dark background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.