/****
* Classes
****/
// Board class representing the game board
var Board = Container.expand(function () {
var self = Container.call(this);
self.cookies = [];
self.rows = 10;
self.cols = 10;
self.initBoard = function () {
var cookieWidth = LK.getAsset('cookie', {}).width;
var cookieHeight = LK.getAsset('cookie', {}).height;
self.rows = Math.floor(2732 / cookieHeight);
self.cols = Math.floor(2048 / cookieWidth);
for (var i = 0; i < self.rows; i++) {
self.cookies[i] = [];
for (var j = 0; j < self.cols; j++) {
var cookie = new Cookie();
cookie.x = j * cookieWidth;
cookie.y = i * cookieHeight;
self.cookies[i][j] = cookie;
self.addChild(cookie);
}
}
};
self.swapCookies = function (cookie1, cookie2) {
// Swap logic for cookies
var tempX = cookie1.x;
var tempY = cookie1.y;
cookie1.x = cookie2.x;
cookie1.y = cookie2.y;
cookie2.x = tempX;
cookie2.y = tempY;
};
self.checkMatches = function () {
for (var i = 0; i < self.rows; i++) {
for (var j = 0; j < self.cols; j++) {
if (self.cookies[i][j] && self.cookies[i][j + 1] && self.cookies[i][j + 2]) {
if (self.cookies[i][j].type === self.cookies[i][j + 1].type && self.cookies[i][j].type === self.cookies[i][j + 2].type) {
return [self.cookies[i][j], self.cookies[i][j + 1], self.cookies[i][j + 2]];
}
}
if (self.cookies[i][j] && self.cookies[i + 1] && self.cookies[i + 2]) {
if (self.cookies[i][j].type === self.cookies[i + 1][j].type && self.cookies[i][j].type === self.cookies[i + 2][j].type) {
return [self.cookies[i][j], self.cookies[i + 1][j], self.cookies[i + 2][j]];
}
}
}
}
return null;
};
self.removeMatches = function () {
var matches = self.checkMatches();
if (matches) {
matches.forEach(function (cookie) {
self.removeChild(cookie);
var index = self.cookies.indexOf(cookie);
if (index > -1) {
self.cookies.splice(index, 1);
}
});
LK.getSound('Match').play();
LK.setScore(LK.getScore() + 10);
}
};
self.fillEmptySpaces = function () {
for (var i = 0; i < self.rows; i++) {
for (var j = 0; j < self.cols; j++) {
if (!self.cookies[i][j]) {
var newCookie = new Cookie();
newCookie.x = j * 100 + 100;
newCookie.y = i * 100 + 100;
self.cookies[i][j] = newCookie;
self.addChild(newCookie);
}
}
}
};
self.update = function () {
// Update logic for the board
};
});
//<Assets used in the game will automatically appear here>
// Cookie class representing each cookie on the board
var Cookie = Container.expand(function () {
var self = Container.call(this);
var cookieGraphics;
switch (self.type) {
case 0:
cookieGraphics = self.attachAsset('cookie', {
anchorX: 0.5,
anchorY: 0.5
});
break;
case 1:
cookieGraphics = self.attachAsset('cookie2', {
anchorX: 0.5,
anchorY: 0.5
});
break;
case 2:
cookieGraphics = self.attachAsset('cookie3', {
anchorX: 0.5,
anchorY: 0.5
});
break;
default:
cookieGraphics = self.attachAsset('cookie', {
anchorX: 0.5,
anchorY: 0.5
});
break;
}
self.type = Math.floor(Math.random() * 3); // Random type for cookie
self.update = function () {
// Update logic for cookies if needed
};
self.down = function (x, y, obj) {
game.handleCookieSelection(self);
game.draggingCookie = self;
LK.getSound('Select').play();
};
self.move = function (x, y, obj) {
if (game.draggingCookie === self) {
self.x = x;
self.y = y;
}
};
self.up = function (x, y, obj) {
if (game.draggingCookie === self) {
game.draggingCookie = null;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var board = new Board();
board.initBoard();
game.addChild(board);
game.selectedCookie = null;
game.draggingCookie = null;
game.handleCookieSelection = function (cookie) {
if (game.selectedCookie) {
board.swapCookies(game.selectedCookie, cookie);
board.removeMatches();
board.fillEmptySpaces();
game.selectedCookie = null;
} else {
game.selectedCookie = cookie;
}
};
var timer = new Text2('0', {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(timer);
var time = 6000;
game.update = function () {
// Update logic for the game
board.update();
if (LK.ticks % 60 == 0) {
time--;
timer.setText(time);
if (time <= 0) {
LK.showGameOver();
}
}
}; /****
* Classes
****/
// Board class representing the game board
var Board = Container.expand(function () {
var self = Container.call(this);
self.cookies = [];
self.rows = 10;
self.cols = 10;
self.initBoard = function () {
var cookieWidth = LK.getAsset('cookie', {}).width;
var cookieHeight = LK.getAsset('cookie', {}).height;
self.rows = Math.floor(2732 / cookieHeight);
self.cols = Math.floor(2048 / cookieWidth);
for (var i = 0; i < self.rows; i++) {
self.cookies[i] = [];
for (var j = 0; j < self.cols; j++) {
var cookie = new Cookie();
cookie.x = j * cookieWidth;
cookie.y = i * cookieHeight;
self.cookies[i][j] = cookie;
self.addChild(cookie);
}
}
};
self.swapCookies = function (cookie1, cookie2) {
// Swap logic for cookies
var tempX = cookie1.x;
var tempY = cookie1.y;
cookie1.x = cookie2.x;
cookie1.y = cookie2.y;
cookie2.x = tempX;
cookie2.y = tempY;
};
self.checkMatches = function () {
for (var i = 0; i < self.rows; i++) {
for (var j = 0; j < self.cols; j++) {
if (self.cookies[i][j] && self.cookies[i][j + 1] && self.cookies[i][j + 2]) {
if (self.cookies[i][j].type === self.cookies[i][j + 1].type && self.cookies[i][j].type === self.cookies[i][j + 2].type) {
return [self.cookies[i][j], self.cookies[i][j + 1], self.cookies[i][j + 2]];
}
}
if (self.cookies[i][j] && self.cookies[i + 1] && self.cookies[i + 2]) {
if (self.cookies[i][j].type === self.cookies[i + 1][j].type && self.cookies[i][j].type === self.cookies[i + 2][j].type) {
return [self.cookies[i][j], self.cookies[i + 1][j], self.cookies[i + 2][j]];
}
}
}
}
return null;
};
self.removeMatches = function () {
var matches = self.checkMatches();
if (matches) {
matches.forEach(function (cookie) {
self.removeChild(cookie);
var index = self.cookies.indexOf(cookie);
if (index > -1) {
self.cookies.splice(index, 1);
}
});
LK.getSound('Match').play();
LK.setScore(LK.getScore() + 10);
}
};
self.fillEmptySpaces = function () {
for (var i = 0; i < self.rows; i++) {
for (var j = 0; j < self.cols; j++) {
if (!self.cookies[i][j]) {
var newCookie = new Cookie();
newCookie.x = j * 100 + 100;
newCookie.y = i * 100 + 100;
self.cookies[i][j] = newCookie;
self.addChild(newCookie);
}
}
}
};
self.update = function () {
// Update logic for the board
};
});
//<Assets used in the game will automatically appear here>
// Cookie class representing each cookie on the board
var Cookie = Container.expand(function () {
var self = Container.call(this);
var cookieGraphics;
switch (self.type) {
case 0:
cookieGraphics = self.attachAsset('cookie', {
anchorX: 0.5,
anchorY: 0.5
});
break;
case 1:
cookieGraphics = self.attachAsset('cookie2', {
anchorX: 0.5,
anchorY: 0.5
});
break;
case 2:
cookieGraphics = self.attachAsset('cookie3', {
anchorX: 0.5,
anchorY: 0.5
});
break;
default:
cookieGraphics = self.attachAsset('cookie', {
anchorX: 0.5,
anchorY: 0.5
});
break;
}
self.type = Math.floor(Math.random() * 3); // Random type for cookie
self.update = function () {
// Update logic for cookies if needed
};
self.down = function (x, y, obj) {
game.handleCookieSelection(self);
game.draggingCookie = self;
LK.getSound('Select').play();
};
self.move = function (x, y, obj) {
if (game.draggingCookie === self) {
self.x = x;
self.y = y;
}
};
self.up = function (x, y, obj) {
if (game.draggingCookie === self) {
game.draggingCookie = null;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var board = new Board();
board.initBoard();
game.addChild(board);
game.selectedCookie = null;
game.draggingCookie = null;
game.handleCookieSelection = function (cookie) {
if (game.selectedCookie) {
board.swapCookies(game.selectedCookie, cookie);
board.removeMatches();
board.fillEmptySpaces();
game.selectedCookie = null;
} else {
game.selectedCookie = cookie;
}
};
var timer = new Text2('0', {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(timer);
var time = 6000;
game.update = function () {
// Update logic for the game
board.update();
if (LK.ticks % 60 == 0) {
time--;
timer.setText(time);
if (time <= 0) {
LK.showGameOver();
}
}
};