/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Card = Container.expand(function (cardType) { var self = Container.call(this); self.cardType = cardType; self.isFlipped = false; self.isMatched = false; self.isRevealed = false; self.cardBack = self.attachAsset('cardBack', { anchorX: 0.5, anchorY: 0.5 }); self.cardFront = self.attachAsset('cardFront' + cardType, { anchorX: 0.5, anchorY: 0.5 }); self.cardFront.visible = false; self.showFront = function () { if (self.isMatched) return; self.cardBack.visible = false; self.cardFront.visible = true; self.isFlipped = true; LK.getSound('cardFlip').play(); }; self.showBack = function () { if (self.isMatched) return; self.cardBack.visible = true; self.cardFront.visible = false; self.isFlipped = false; }; self.setMatched = function () { self.isMatched = true; self.isFlipped = true; tween(self, { alpha: 0 }, { duration: 500 }); }; self.down = function (x, y, obj) { if (gameState !== 'playing' || self.isMatched || self.isFlipped) return; if (flippedCards.length >= 2) return; self.showFront(); flippedCards.push(self); if (flippedCards.length === 2) { LK.setTimeout(function () { checkMatch(); }, 1000); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xcc0000 }); /**** * Game Code ****/ var cards = []; var flippedCards = []; var gameState = 'preview'; // 'preview', 'playing', 'finished' var previewTimer = null; var pairsFound = 0; var score = 0; var gameTimeLeft = 30; var gameTimer = null; // Create scoreboard in upper left var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0, 0); scoreText.x = 120; // Offset from top-left to avoid platform menu icon scoreText.y = 20; LK.gui.topLeft.addChild(scoreText); // Create game timer in upper right var gameTimerText = new Text2('30', { size: 60, fill: 0xFFFFFF }); gameTimerText.anchor.set(1, 0); gameTimerText.x = 2048 - 20; gameTimerText.y = 20; LK.gui.topRight.addChild(gameTimerText); // Create timer icon next to timer text var timerIcon = LK.getAsset('timerIcon', { anchorX: 1, anchorY: 0, scaleX: 1.5, scaleY: 1.5 }); timerIcon.x = -80; timerIcon.y = 20; LK.gui.topRight.addChild(timerIcon); var timerText = new Text2('10', { size: 120, fill: 0xFFFFFF }); timerText.anchor.set(0.5, 0); LK.gui.top.addChild(timerText); var instructionText = new Text2('Ülker Lezzet Evreni', { size: 80, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 1); LK.gui.bottom.addChild(instructionText); // Create shuffled array of card types (18 pairs) var cardTypes = []; var validCardTypes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 17, 18]; for (var i = 0; i < validCardTypes.length; i++) { cardTypes.push(validCardTypes[i]); cardTypes.push(validCardTypes[i]); } // Add 4 more pairs to make 18 total pairs (36 cards for 6x6 grid) for (var i = 0; i < 4; i++) { cardTypes.push(validCardTypes[i]); cardTypes.push(validCardTypes[i]); } // Shuffle the array for (var i = cardTypes.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = cardTypes[i]; cardTypes[i] = cardTypes[j]; cardTypes[j] = temp; } // Create 6x6 grid of cards var cardIndex = 0; var startX = 2048 / 2 - 6 * 280 / 2 + 140; var startY = 2732 / 2 - 6 * 280 / 2 + 240; for (var row = 0; row < 6; row++) { for (var col = 0; col < 6; col++) { var card = new Card(cardTypes[cardIndex]); card.x = startX + col * 280; card.y = startY + row * 280; cards.push(card); game.addChild(card); cardIndex++; } } // Start with preview mode - show all cards for 10 seconds gameState = 'preview'; instructionText.setText('Hafızana güven!'); var previewTimeLeft = 10; timerText.setText(previewTimeLeft.toString()); // Show all cards front immediately during preview for (var i = 0; i < cards.length; i++) { cards[i].cardBack.visible = false; cards[i].cardFront.visible = true; cards[i].isFlipped = true; cards[i].isRevealed = true; } // Start preview countdown timer previewTimer = LK.setInterval(function () { previewTimeLeft--; timerText.setText(previewTimeLeft.toString()); if (previewTimeLeft <= 0) { LK.clearInterval(previewTimer); // Flip all cards back and start the game for (var i = 0; i < cards.length; i++) { cards[i].showBack(); cards[i].isRevealed = false; } gameState = 'playing'; instructionText.setText('Ülker Lezzet Evreni'); timerText.setText(''); // Start 30 second game timer gameTimer = LK.setInterval(function () { gameTimeLeft--; gameTimerText.setText(gameTimeLeft.toString()); // Add visual feedback when time is running low if (gameTimeLeft <= 10) { tween(gameTimerText, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(gameTimerText, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); if (gameTimeLeft <= 5) { gameTimerText.tint = 0xFF0000; // Red color for urgency } } // Add timer icon pulse animation every second tween(timerIcon, { scaleX: 2.0, scaleY: 2.0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { tween(timerIcon, { scaleX: 1.5, scaleY: 1.5 }, { duration: 300, easing: tween.easeIn }); } }); if (gameTimeLeft <= 0) { LK.clearInterval(gameTimer); gameState = 'finished'; LK.showGameOver(); } }, 1000); } }, 1000); function checkMatch() { if (flippedCards.length !== 2) return; var card1 = flippedCards[0]; var card2 = flippedCards[1]; if (card1.cardType === card2.cardType) { // Match found card1.setMatched(); card2.setMatched(); pairsFound++; score += 10; scoreText.setText('Score: ' + score); LK.getSound('matchFound').play(); // Create star particle effect for (var p = 0; p < 12; p++) { var star = LK.getAsset('starParticle', { anchorX: 0.5, anchorY: 0.5 }); star.x = (card1.x + card2.x) / 2; star.y = (card1.y + card2.y) / 2; star.rotation = Math.random() * Math.PI * 2; star.scaleX = 0.5 + Math.random() * 0.5; star.scaleY = star.scaleX; game.addChild(star); var angle = p / 12 * Math.PI * 2 + Math.random() * 0.5; var distance = 80 + Math.random() * 120; var targetX = star.x + Math.cos(angle) * distance; var targetY = star.y + Math.sin(angle) * distance; tween(star, { x: targetX, y: targetY, alpha: 0, scaleX: 0.1, scaleY: 0.1, rotation: star.rotation + Math.PI * 4 }, { duration: 1000 + Math.random() * 500, easing: tween.easeOut, onFinish: function onFinish() { star.destroy(); } }); } if (pairsFound === 18) { gameState = 'finished'; if (gameTimer) { LK.clearInterval(gameTimer); } LK.setTimeout(function () { LK.showYouWin(); }, 1000); } } else { // No match, flip back card1.showBack(); card2.showBack(); } flippedCards = []; } game.update = function () { // Game logic handled by events and timers };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Card = Container.expand(function (cardType) {
var self = Container.call(this);
self.cardType = cardType;
self.isFlipped = false;
self.isMatched = false;
self.isRevealed = false;
self.cardBack = self.attachAsset('cardBack', {
anchorX: 0.5,
anchorY: 0.5
});
self.cardFront = self.attachAsset('cardFront' + cardType, {
anchorX: 0.5,
anchorY: 0.5
});
self.cardFront.visible = false;
self.showFront = function () {
if (self.isMatched) return;
self.cardBack.visible = false;
self.cardFront.visible = true;
self.isFlipped = true;
LK.getSound('cardFlip').play();
};
self.showBack = function () {
if (self.isMatched) return;
self.cardBack.visible = true;
self.cardFront.visible = false;
self.isFlipped = false;
};
self.setMatched = function () {
self.isMatched = true;
self.isFlipped = true;
tween(self, {
alpha: 0
}, {
duration: 500
});
};
self.down = function (x, y, obj) {
if (gameState !== 'playing' || self.isMatched || self.isFlipped) return;
if (flippedCards.length >= 2) return;
self.showFront();
flippedCards.push(self);
if (flippedCards.length === 2) {
LK.setTimeout(function () {
checkMatch();
}, 1000);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xcc0000
});
/****
* Game Code
****/
var cards = [];
var flippedCards = [];
var gameState = 'preview'; // 'preview', 'playing', 'finished'
var previewTimer = null;
var pairsFound = 0;
var score = 0;
var gameTimeLeft = 30;
var gameTimer = null;
// Create scoreboard in upper left
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 120; // Offset from top-left to avoid platform menu icon
scoreText.y = 20;
LK.gui.topLeft.addChild(scoreText);
// Create game timer in upper right
var gameTimerText = new Text2('30', {
size: 60,
fill: 0xFFFFFF
});
gameTimerText.anchor.set(1, 0);
gameTimerText.x = 2048 - 20;
gameTimerText.y = 20;
LK.gui.topRight.addChild(gameTimerText);
// Create timer icon next to timer text
var timerIcon = LK.getAsset('timerIcon', {
anchorX: 1,
anchorY: 0,
scaleX: 1.5,
scaleY: 1.5
});
timerIcon.x = -80;
timerIcon.y = 20;
LK.gui.topRight.addChild(timerIcon);
var timerText = new Text2('10', {
size: 120,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
var instructionText = new Text2('Ülker Lezzet Evreni', {
size: 80,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
// Create shuffled array of card types (18 pairs)
var cardTypes = [];
var validCardTypes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 17, 18];
for (var i = 0; i < validCardTypes.length; i++) {
cardTypes.push(validCardTypes[i]);
cardTypes.push(validCardTypes[i]);
}
// Add 4 more pairs to make 18 total pairs (36 cards for 6x6 grid)
for (var i = 0; i < 4; i++) {
cardTypes.push(validCardTypes[i]);
cardTypes.push(validCardTypes[i]);
}
// Shuffle the array
for (var i = cardTypes.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = cardTypes[i];
cardTypes[i] = cardTypes[j];
cardTypes[j] = temp;
}
// Create 6x6 grid of cards
var cardIndex = 0;
var startX = 2048 / 2 - 6 * 280 / 2 + 140;
var startY = 2732 / 2 - 6 * 280 / 2 + 240;
for (var row = 0; row < 6; row++) {
for (var col = 0; col < 6; col++) {
var card = new Card(cardTypes[cardIndex]);
card.x = startX + col * 280;
card.y = startY + row * 280;
cards.push(card);
game.addChild(card);
cardIndex++;
}
}
// Start with preview mode - show all cards for 10 seconds
gameState = 'preview';
instructionText.setText('Hafızana güven!');
var previewTimeLeft = 10;
timerText.setText(previewTimeLeft.toString());
// Show all cards front immediately during preview
for (var i = 0; i < cards.length; i++) {
cards[i].cardBack.visible = false;
cards[i].cardFront.visible = true;
cards[i].isFlipped = true;
cards[i].isRevealed = true;
}
// Start preview countdown timer
previewTimer = LK.setInterval(function () {
previewTimeLeft--;
timerText.setText(previewTimeLeft.toString());
if (previewTimeLeft <= 0) {
LK.clearInterval(previewTimer);
// Flip all cards back and start the game
for (var i = 0; i < cards.length; i++) {
cards[i].showBack();
cards[i].isRevealed = false;
}
gameState = 'playing';
instructionText.setText('Ülker Lezzet Evreni');
timerText.setText('');
// Start 30 second game timer
gameTimer = LK.setInterval(function () {
gameTimeLeft--;
gameTimerText.setText(gameTimeLeft.toString());
// Add visual feedback when time is running low
if (gameTimeLeft <= 10) {
tween(gameTimerText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(gameTimerText, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
if (gameTimeLeft <= 5) {
gameTimerText.tint = 0xFF0000; // Red color for urgency
}
}
// Add timer icon pulse animation every second
tween(timerIcon, {
scaleX: 2.0,
scaleY: 2.0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(timerIcon, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeIn
});
}
});
if (gameTimeLeft <= 0) {
LK.clearInterval(gameTimer);
gameState = 'finished';
LK.showGameOver();
}
}, 1000);
}
}, 1000);
function checkMatch() {
if (flippedCards.length !== 2) return;
var card1 = flippedCards[0];
var card2 = flippedCards[1];
if (card1.cardType === card2.cardType) {
// Match found
card1.setMatched();
card2.setMatched();
pairsFound++;
score += 10;
scoreText.setText('Score: ' + score);
LK.getSound('matchFound').play();
// Create star particle effect
for (var p = 0; p < 12; p++) {
var star = LK.getAsset('starParticle', {
anchorX: 0.5,
anchorY: 0.5
});
star.x = (card1.x + card2.x) / 2;
star.y = (card1.y + card2.y) / 2;
star.rotation = Math.random() * Math.PI * 2;
star.scaleX = 0.5 + Math.random() * 0.5;
star.scaleY = star.scaleX;
game.addChild(star);
var angle = p / 12 * Math.PI * 2 + Math.random() * 0.5;
var distance = 80 + Math.random() * 120;
var targetX = star.x + Math.cos(angle) * distance;
var targetY = star.y + Math.sin(angle) * distance;
tween(star, {
x: targetX,
y: targetY,
alpha: 0,
scaleX: 0.1,
scaleY: 0.1,
rotation: star.rotation + Math.PI * 4
}, {
duration: 1000 + Math.random() * 500,
easing: tween.easeOut,
onFinish: function onFinish() {
star.destroy();
}
});
}
if (pairsFound === 18) {
gameState = 'finished';
if (gameTimer) {
LK.clearInterval(gameTimer);
}
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
}
} else {
// No match, flip back
card1.showBack();
card2.showBack();
}
flippedCards = [];
}
game.update = function () {
// Game logic handled by events and timers
};