User prompt
Implement " //Implement that the below code is repeated until no changed occur"
Code edit (1 edits merged)
Please save this source code
User prompt
Implement "//Move the gem here directly"
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'self.grid[gem1.row][gem1.col] = undefined;' Line Number: 77
User prompt
In the code where we ask you to move down all gems into available space here, write the code that would detect if there's an empty spot below a given gem and move it down if that's the case.
Code edit (1 edits merged)
Please save this source code
User prompt
In the check match method on the board, please make sure that matches can both happen horizontally and vertically at the same time.
User prompt
In the checkMatch method, it looks like a gem can only be part of one match. That is not how match tree games work. Any gem can be a member of multiple matches at the same time. Please fix this.
User prompt
In the game down method where we are doing debugging, rather than just logging out the matches, loop over all the matches and set the alpha on the gems that have been matched to half opacity, set all other grid nodes to full opacity.
Code edit (1 edits merged)
Please save this source code
User prompt
updateCheckMatch() method to allow for matches of three or more rather than only three as it is right now.
Code edit (2 edits merged)
Please save this source code
User prompt
Add a method on board that loops over the entire board and determine if there's any free matches on the horizontal or the vertical direction. Create an array of those matches.
Code edit (3 edits merged)
Please save this source code
User prompt
While we are asking to InsetLogic to swap in other directions as well, please make sure that we can swap in both x-directions and in both y-directions.
Code edit (1 edits merged)
Please save this source code
User prompt
Where it says "//Swap this gem with its gem on the left." please implement this logic
User prompt
In the Swap Gems method on board, please make sure that the row and column values on each individual gems are also correctly swapped.
Code edit (1 edits merged)
Please save this source code
User prompt
In gem after generating type where you attach a gem element use five different types of gems
Code edit (6 edits merged)
Please save this source code
User prompt
So, please add a method to the board that allows me to swap two gems.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // Class for the game board var Board = Container.expand(function () { var self = Container.call(this); self.grid = []; self.rows = 8; self.cols = 8; self.spacing = 10; var mesureGem = new Gem(); self.gemSize = mesureGem.width + self.spacing; self.init = function () { for (var row = 0; row < self.rows; row++) { self.grid[row] = []; for (var col = 0; col < self.cols; col++) { var gem = new Gem(); gem.x = gem.targetX = col * self.gemSize; gem.y = gem.targetY = row * self.gemSize; gem.col = col; gem.row = row; self.grid[row][col] = gem; self.addChild(gem); } } }; // Method to swap two gems self.swapGems = function (gem1, gem2) { var temp = self.grid[gem1.row][gem1.col]; self.grid[gem1.row][gem1.col] = self.grid[gem2.row][gem2.col]; self.grid[gem2.row][gem2.col] = temp; var tempX = gem1.targetX; var tempY = gem1.targetY; var tempRow = gem1.row; var tempCol = gem1.col; gem1.targetX = gem2.targetX; gem1.targetY = gem2.targetY; gem1.row = gem2.row; gem1.col = gem2.col; gem2.targetX = tempX; gem2.targetY = tempY; gem2.row = tempRow; gem2.col = tempCol; }; }); //<Assets used in the game will automatically appear here> // Class for a single gem var Gem = Container.expand(function () { var self = Container.call(this); self.type = Math.floor(Math.random() * 5); // Random type for the gem self.row = 0; self.col = 0; var gemGraphics; switch (self.type) { case 0: gemGraphics = self.attachAsset('gem1', { anchorX: 0.5, anchorY: 0.5 }); break; case 1: gemGraphics = self.attachAsset('gem2', { anchorX: 0.5, anchorY: 0.5 }); break; case 2: gemGraphics = self.attachAsset('gem3', { anchorX: 0.5, anchorY: 0.5 }); break; case 3: gemGraphics = self.attachAsset('gem4', { anchorX: 0.5, anchorY: 0.5 }); break; case 4: gemGraphics = self.attachAsset('gem5', { anchorX: 0.5, anchorY: 0.5 }); break; } self.targetX = 0; self.targetY = 0; self.update = function () { // Update logic for the gem if needed }; self.down = function (x, y, obj) { // Logic for selecting the gem game.selectGem(self, x, y); }; self.update = function () { if (currentDragNode != self) { self.x += (self.targetX - self.x) / 7; self.y += (self.targetY - self.y) / 7; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var selectedGem = null; var board = new Board(); board.x = (2048 - board.cols * board.gemSize + board.gemSize + board.spacing) / 2; board.y = (2732 - board.rows * board.gemSize + board.gemSize + board.spacing) / 2; board.init(); game.addChild(board); var currentDragNode = undefined; var currentDragNodeX = 0; var currentDragNodeY = 0; game.selectGem = function (gem, offsetX, offsetY) { currentDragNode = gem; currentDragNodeX = offsetX; currentDragNodeY = offsetY; board.addChild(gem); }; game.move = function (x, y) { if (currentDragNode) { currentDragNode.x = x - board.x - currentDragNodeX; currentDragNode.y = y - board.y - currentDragNodeY; var offsetX = currentDragNode.targetX - currentDragNode.x; var offsetY = currentDragNode.targetY - currentDragNode.y; if (Math.abs(offsetX) > 75) { console.log("Should swap X"); if (offsetX < 0) { //Swap this gem with its gem on the left. if (currentDragNode.col > 0) { var leftGem = board.grid[currentDragNode.row][currentDragNode.col - 1]; board.swapGems(currentDragNode, leftGem); } } } } }; game.up = function () { currentDragNode = undefined; }; /*game.down = function () { var gem1 = board.grid[Math.random() * 8 >> 0][Math.random() * 8 >> 0]; var gem2 = board.grid[Math.random() * 8 >> 0][Math.random() * 8 >> 0]; board.addChild(gem1); board.addChild(gem2); board.swapGems(gem1, gem2); };*/
===================================================================
--- original.js
+++ change.js
@@ -133,9 +133,13 @@
var offsetY = currentDragNode.targetY - currentDragNode.y;
if (Math.abs(offsetX) > 75) {
console.log("Should swap X");
if (offsetX < 0) {
- //Swap this gem with it's gem on the left.
+ //Swap this gem with its gem on the left.
+ if (currentDragNode.col > 0) {
+ var leftGem = board.grid[currentDragNode.row][currentDragNode.col - 1];
+ board.swapGems(currentDragNode, leftGem);
+ }
}
}
}
};