User prompt
Please fix the bug: 'Uncaught ReferenceError: foundRedSquares is not defined' in or related to this line: 'debugText.setText('Red squares revealed: ' + ++foundRedSquares);' Line Number: 70
User prompt
Create a system which tracks what colored squares are revealed
User prompt
Add a debug tool into the game which shows the number of red squares revealed
User prompt
The overlay sqaure is using the graySquare asset, not the overgraySquare asset. Please use the overgraySquare asset for that.
User prompt
If a red square is revealed after an overlay gray square is clicked, end the game
User prompt
When you click on a gray square, make the square below it clicked also
User prompt
Make it so the underlying red square ends the game if the overlay square is clicked
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'self.underlyingSquare.destroy();' Line Number: 22
User prompt
Make it so the overlay square clicked corresponds with the square below it
User prompt
The current squares over the previous squares are red, not gray. Please make those squares a new shape called "overgraySquare" and make those the overlay
User prompt
Make another layer of squares over the current squares which are gray and be clicked to be removed
User prompt
Please fix the bug: 'Uncaught TypeError: squareGraphics.setTexture is not a function' in or related to this line: 'squareGraphics.setTexture('greenSquare');' Line Number: 23
Initial prompt
Find The Greens!
/**** * Classes ****/ // Class for the overlay square in the grid var OverlaySquare = Container.expand(function (underlyingSquare) { var self = Container.call(this); self.underlyingSquare = underlyingSquare; var squareGraphics = self.attachAsset('graySquare', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { self.destroy(); self.underlyingSquare.destroy(); }; }); // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // Class for a single square in the grid var Square = Container.expand(function () { var self = Container.call(this); self.isGreen = false; self.isRed = false; // Attach a gray square asset by default var squareGraphics = self.attachAsset('graySquare', { anchorX: 0.5, anchorY: 0.5 }); // Method to set the square as green self.setGreen = function () { self.isGreen = true; squareGraphics = self.attachAsset('greenSquare', { anchorX: 0.5, anchorY: 0.5 }); }; // Method to set the square as red self.setRed = function () { self.isRed = true; squareGraphics = self.attachAsset('redSquare', { anchorX: 0.5, anchorY: 0.5 }); }; // Event handler for when the square is clicked self.down = function (x, y, obj) { if (self.isGreen) { self.destroy(); foundGreenSquares++; if (foundGreenSquares === 5) { LK.showGameOver(true); // Win condition } } else if (self.isRed) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); // Lose condition } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var grid = []; var foundGreenSquares = 0; // Initialize the grid function initializeGrid() { var positions = []; for (var i = 0; i < 25; i++) { positions.push(i); } // Shuffle positions positions.sort(function () { return Math.random() - 0.5; }); // Create squares for (var i = 0; i < 25; i++) { var square = new Square(); var x = i % 5 * 200 + 400; // Centering the grid horizontally var y = Math.floor(i / 5) * 200 + 600; // Centering the grid vertically square.x = x; square.y = y; grid.push(square); game.addChild(square); // Create overlay square var overlaySquare = new OverlaySquare(); overlaySquare.x = x; overlaySquare.y = y; game.addChild(overlaySquare); } // Set 5 green squares for (var i = 0; i < 5; i++) { grid[positions[i]].setGreen(); } // Set 10 red squares for (var i = 5; i < 15; i++) { grid[positions[i]].setRed(); } } // Initialize the game grid initializeGrid();
===================================================================
--- original.js
+++ change.js
@@ -1,18 +1,18 @@
/****
* Classes
****/
// Class for the overlay square in the grid
-var OverlaySquare = Container.expand(function () {
+var OverlaySquare = Container.expand(function (underlyingSquare) {
var self = Container.call(this);
- // Attach a overgray square asset by default
- var squareGraphics = self.attachAsset('overgraySquare', {
+ self.underlyingSquare = underlyingSquare;
+ var squareGraphics = self.attachAsset('graySquare', {
anchorX: 0.5,
anchorY: 0.5
});
- // Event handler for when the square is clicked
self.down = function (x, y, obj) {
self.destroy();
+ self.underlyingSquare.destroy();
};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Class for a single square in the grid