/**** * 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.gemSize = 110; 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 = col * self.gemSize; gem.y = row * self.gemSize; self.grid[row][col] = gem; self.addChild(gem); } } }; self.swapGems = function (gem1, gem2) { // Logic to swap two gems }; self.checkMatches = function () { // Logic to check for matches }; self.removeMatches = function () { // Logic to remove matched gems }; self.fillEmptySpaces = function () { // Logic to fill empty spaces after removing matches }; self.update = function () { // Update logic for the board }; }); //<Assets used in the game will automatically appear here> // Class for a single gem var Gem = Container.expand(function () { var self = Container.call(this); var gemGraphics = self.attachAsset('gem', { anchorX: 0.5, anchorY: 0.5 }); self.type = Math.floor(Math.random() * 5); // Random type for the gem self.update = function () { // Update logic for the gem if needed }; self.down = function (x, y, obj) { // Logic for selecting the gem game.selectGem(self); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var board; var selectedGem = null; game.init = function () { board = new Board(); board.x = (2048 - board.cols * board.gemSize) / 2; board.y = (2732 - board.rows * board.gemSize) / 2; board.init(); game.addChild(board); }; game.selectGem = function (gem) { if (selectedGem) { board.swapGems(selectedGem, gem); selectedGem = null; } else { selectedGem = gem; } }; game.update = function () { board.update(); // Additional game update logic }; game.init();
===================================================================
--- original.js
+++ change.js
@@ -1,88 +1,88 @@
-/****
+/****
* 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.gemSize = 100;
- 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 = col * self.gemSize;
- gem.y = row * self.gemSize;
- self.grid[row][col] = gem;
- self.addChild(gem);
- }
- }
- };
- self.swapGems = function (gem1, gem2) {
- // Logic to swap two gems
- };
- self.checkMatches = function () {
- // Logic to check for matches
- };
- self.removeMatches = function () {
- // Logic to remove matched gems
- };
- self.fillEmptySpaces = function () {
- // Logic to fill empty spaces after removing matches
- };
- self.update = function () {
- // Update logic for the board
- };
+ var self = Container.call(this);
+ self.grid = [];
+ self.rows = 8;
+ self.cols = 8;
+ self.gemSize = 110;
+ 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 = col * self.gemSize;
+ gem.y = row * self.gemSize;
+ self.grid[row][col] = gem;
+ self.addChild(gem);
+ }
+ }
+ };
+ self.swapGems = function (gem1, gem2) {
+ // Logic to swap two gems
+ };
+ self.checkMatches = function () {
+ // Logic to check for matches
+ };
+ self.removeMatches = function () {
+ // Logic to remove matched gems
+ };
+ self.fillEmptySpaces = function () {
+ // Logic to fill empty spaces after removing matches
+ };
+ self.update = function () {
+ // Update logic for the board
+ };
});
//<Assets used in the game will automatically appear here>
// Class for a single gem
var Gem = Container.expand(function () {
- var self = Container.call(this);
- var gemGraphics = self.attachAsset('gem', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.type = Math.floor(Math.random() * 5); // Random type for the gem
- self.update = function () {
- // Update logic for the gem if needed
- };
- self.down = function (x, y, obj) {
- // Logic for selecting the gem
- game.selectGem(self);
- };
+ var self = Container.call(this);
+ var gemGraphics = self.attachAsset('gem', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = Math.floor(Math.random() * 5); // Random type for the gem
+ self.update = function () {
+ // Update logic for the gem if needed
+ };
+ self.down = function (x, y, obj) {
+ // Logic for selecting the gem
+ game.selectGem(self);
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var board;
var selectedGem = null;
game.init = function () {
- board = new Board();
- board.x = (2048 - board.cols * board.gemSize) / 2;
- board.y = (2732 - board.rows * board.gemSize) / 2;
- board.init();
- game.addChild(board);
+ board = new Board();
+ board.x = (2048 - board.cols * board.gemSize) / 2;
+ board.y = (2732 - board.rows * board.gemSize) / 2;
+ board.init();
+ game.addChild(board);
};
game.selectGem = function (gem) {
- if (selectedGem) {
- board.swapGems(selectedGem, gem);
- selectedGem = null;
- } else {
- selectedGem = gem;
- }
+ if (selectedGem) {
+ board.swapGems(selectedGem, gem);
+ selectedGem = null;
+ } else {
+ selectedGem = gem;
+ }
};
game.update = function () {
- board.update();
- // Additional game update logic
+ board.update();
+ // Additional game update logic
};
game.init();
\ No newline at end of file