Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting '3')' in or related to this line: 'currentLevel[self.gridY][self.gridX] = self.colorIndex;' Line Number: 189
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < a.length; i++) {' Line Number: 357
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < a.length; i++) {' Line Number: 357
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < a.length; i++) {' Line Number: 357
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: 'TypeError: Cannot set properties of undefined (setting '5')' in or related to this line: 'currentLevel[self.gridY][self.gridX] = self.colorIndex;' Line Number: 189
Code edit (13 edits merged)
Please save this source code
User prompt
Please fix the bug: 'newPosition is not defined' in or related to this line: 'if (newPosition != 999) {' Line Number: 638
Code edit (1 edits merged)
Please save this source code
Code edit (12 edits merged)
Please save this source code
User prompt
Please fix the bug: 'levelContainer.children.findAll is not a function' in or related to this line: 'var outliers = levelContainer.children.findAll(function (child) {' Line Number: 548
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -98,8 +98,9 @@
});
self.gridX = 0;
self.gridY = 0;
self.speed = 10;
+ self.outlier = false;
self.down = function (x, y, obj) {
//console.log(x, y, obj);
colorBoxClicked(self);
};
@@ -368,15 +369,112 @@
t[i].remove(i * 30);
}
}
function placeOutliers() {
+ // Determine colors left on the board to choose from.
var colorsPresent = [];
var gridSize = currentLevel.length;
for (var i = 0; i < gridSize; i++) {
- for (var j = 0; j < gridSize; j++) {}
+ for (var j = 0; j < gridSize; j++) {
+ var t = currentLevel[i][j];
+ if (t != 0 && !colorsPresent.includes(t)) {
+ colorsPresent.push(t);
+ }
+ }
}
+ console.log('Game still includes these colors:', colorsPresent);
// Determine what rows and cols contain colorboxes.
- // Determine amount of outliers to place
- // Determine colors left on the board to choose from, and set outlier colors
+ // Horizontal rows
+ var availableRows = [];
+ for (var i = 0; i < gridSize; i++) {
+ if (currentLevel[i].some(checkNonZero)) {
+ console.log('there are non-zero values in row:', i);
+ availableRows.push(i);
+ }
+ }
+ // Vertical columns
+ var availableCols = [];
+ var cols = rotateMatrix90C(currentLevel);
+ for (var i = 0; i < gridSize; i++) {
+ if (cols[i].some(checkNonZero)) {
+ console.log('there are non-zero values in col:', i);
+ availableCols.push(i);
+ }
+ }
+ // If no available rows or cols left, level cleared!
+ var n = availableRows.length + availableCols.length;
+ console.log(n);
+ if (n === 0) {
+ console.log('level cleared. TODO: write level cleared function.');
+ } else {
+ // Place an outlier tile at 50% (and minimum one) of the available positions.
+ var placedAtLeastOne = false;
+ console.log('ac:', availableCols);
+ availableCols = shuffleArray(availableCols);
+ availableRows = shuffleArray(availableRows);
+ console.log('ac:', availableCols);
+ for (var i = 0; i < availableRows; i++) {
+ if (Math.random() < 0.5 || !placedAtLeastOne) {
+ // place it, either side will do.
+ var cIndex = colorsPresent[Math.floor(Math.random() * colorsPresent.length)];
+ var b = new ColorBox(cIndex);
+ b.outlier = true;
+ cBox.width = cBox.height = tileSize;
+ if (Math.random() < 0.5) {
+ b.x = -1000;
+ b.y = 0; // determine this
+ b.gridX = 0; // determine this
+ b.gridY = i;
+ } else {
+ b.x = 1000;
+ b.y = 0; // determine this
+ b.gridX = 0; // determine this
+ b.gridY = i;
+ }
+ // Tween into place.
+ levelContainer.addChild(b);
+ console.log('levelContainer is now:', levelContainer);
+ placedAtLeastOne = true;
+ }
+ }
+ for (var i = 0; i < availableCols; i++) {
+ if (Math.random() < 0.5) {
+ // place it, either side will do
+ } else {}
+ }
+ }
// And place them. (Animate them in from sides.)
}
+function shuffleArray(arr) {
+ var j, x, index;
+ for (index = arr.length - 1; index > 0; index--) {
+ j = Math.floor(Math.random() * (index + 1));
+ x = arr[index];
+ arr[index] = arr[j];
+ arr[j] = x;
+ }
+ return arr;
+}
+function checkNonZero(i) {
+ return i != 0;
+}
+function rotateMatrix90C(source) {
+ // get the dimensions of the source matrix
+ var m = source.length;
+ var n = source[0].length;
+ // create a new NxM destination array
+ var destination = new Array(n);
+ for (var i = 0; i < n; i++) {
+ destination[i] = new Array(m);
+ }
+ // start copying from source into destination
+ for (var i = 0; i < n; i++) {
+ for (var j = 0; j < m; j++) {
+ destination[i][j] = source[m - j - 1][i];
+ }
+ }
+ // return the destination matrix
+ return destination;
+}
+;
+placeOutliers();
function moveIn() {}
\ No newline at end of file
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.