User prompt
Rename this current menu to cardgame menu
User prompt
Add pairL to selectable type of card pairs
User prompt
Add pairK to selectable type of card pairs
User prompt
There is a pair bug on level5. Pair all of cards with correctly.
User prompt
U can use pairs for more times at level5 to fix pair bug
User prompt
fix card pair bug on level5
User prompt
Skip center card creation for level 5 to avoid pair fail in 5x5 grid
User prompt
If a card pair has already been loaded for a given level, that pair should appear only once on levels 1, 2, 3, and 4, and there should be no repeated pairs on these levels. In level 5 it is allowed, because there are 10 card pairs from A to J, and level 5 contains a total of 25 cards. Distribute the cards accordingly.
User prompt
Move all the cards on level4 down by 123 units
User prompt
I asked you to pair the cards correctly but you still didn't
User prompt
Also fix this card pair bug on each level
User prompt
There is a bug on level 1: the game does not always generate the cards in pairs. In some cases, it does not deal the matching pair for one of the cards, which results in an odd card and makes the level unsolvable. Fix this and prevent this error from happening.
User prompt
Remove the center card from the level1 card grid to avoid pair fail.
User prompt
Change Card Arrangements by Levels tobthis grid: 3x3 on level1, 3x4 on level2, 4x4 on level3, 4x5 on level4, 5x5 on level5
User prompt
Moves, time, level text shoul not visible on menu
User prompt
Show Level: 2 text in the level 2 map
User prompt
Display The level numbers are not correct on the levels. Every levels shows just level1 number. Fix it to show the correct level number.
User prompt
Move all levelbuttons left by 25 units
User prompt
Move all levelbuttons left by 30 units
User prompt
Move all levelbuttons left by 100 units
User prompt
Move all levelbuttons right by 300 units
User prompt
Add Level 6 to the game.
User prompt
Move all level buttons right by 500 unit
User prompt
Center of Level3 button should be in the center of the screen. Move all level buttons with it to fit in.
User prompt
Increase level buttons size by 1.5 but take the same distance between them
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
bestScore: 0,
level: 1
});
/****
* Classes
****/
var Card = Container.expand(function (cardId, pairId) {
var self = Container.call(this);
self.cardId = cardId;
self.pairId = pairId;
self.isFlipped = false;
self.isMatched = false;
// Card back (shown when not flipped)
var cardBack = self.attachAsset('cardBack', {
anchorX: 0.5,
anchorY: 0.5
});
// Card front (the actual pattern/color)
var cardFront = self.attachAsset('pair' + pairId, {
anchorX: 0.5,
anchorY: 0.5,
visible: false
});
if (pairId === 'J') {
cardFront = self.attachAsset('pairJ', {
anchorX: 0.5,
anchorY: 0.5,
visible: false
});
}
if (pairId === 'K') {
cardFront = self.attachAsset('pairK', {
anchorX: 0.5,
anchorY: 0.5,
visible: false
});
}
if (pairId === 'L') {
cardFront = self.attachAsset('pairL', {
anchorX: 0.5,
anchorY: 0.5,
visible: false
});
}
self.back = cardBack;
self.front = cardFront;
// Method to flip the card
self.flip = function () {
if (self.isMatched || self.isFlipped) {
return false;
}
LK.getSound('flip').play();
self.isFlipped = true;
// Animate the flip
tween(cardBack, {
scaleX: 0
}, {
duration: 150,
easing: tween.easeIn,
onFinish: function onFinish() {
cardBack.visible = false;
cardFront.visible = true;
tween(cardFront, {
scaleX: 1
}, {
duration: 150,
easing: tween.easeOut
});
}
});
return true;
};
// Method to flip back
self.flipBack = function () {
if (self.isMatched || !self.isFlipped) {
return;
}
self.isFlipped = false;
tween(cardFront, {
scaleX: 0
}, {
duration: 150,
easing: tween.easeIn,
onFinish: function onFinish() {
cardFront.visible = false;
cardBack.visible = true;
tween(cardBack, {
scaleX: 1
}, {
duration: 150,
easing: tween.easeOut
});
}
});
};
// Method to mark card as matched
self.setMatched = function () {
self.isMatched = true;
// Create a matched effect
var matchEffect = self.attachAsset('cardMatch', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
tween(matchEffect, {
alpha: 0.7
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
matchEffect.destroy(); // Remove the matched effect after animation
self.removeChild(matchEffect); // Ensure the effect is removed from the display list
}
});
};
// Handle card selection
self.down = function (x, y, obj) {
if (!gameActive || processingMatch || self.isMatched) {
return;
}
var flipped = self.flip();
if (flipped) {
checkForMatch(self);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Updated to use the latest LK engine default background color
});
/****
* Game Code
****/
// Game state variables
var cards = [];
var gridWidth = 4;
var gridHeight = 3;
var cardWidth = 180;
var cardHeight = 250;
var cardSpacing = 200; // Increased vertical spacing between cards
var flippedCards = [];
var gameActive = false;
var processingMatch = false;
var moves = 0;
var pairsFound = 0;
var level = 1;
var totalPairs = gridWidth * gridHeight / 2;
var gameStartTime;
// UI Elements
var titleText = new Text2("Card Game Menu", {
size: 80,
fill: 0xFFA500,
fontWeight: 'bolder'
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
var movesText = new Text2('Moves: 0', {
size: 60,
fill: 0xFFFFFF
});
movesText.anchor.set(0, 0);
LK.gui.topLeft.addChild(movesText);
movesText.x = 120;
movesText.y = 150;
movesText.visible = false;
var levelText = new Text2('Level: ' + level, {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(1, 0);
LK.gui.topRight.addChild(levelText);
levelText.x = -120;
levelText.y = 150;
levelText.visible = false;
var timerText = new Text2('Time: 0s', {
size: 60,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
timerText.y = 150;
timerText.visible = false;
// Level selector buttons
var levelButtons = [];
var levelButtonY = 2732 / 2 - 250;
var buttonSpacing = 337.5;
var centerButtonIndex = 2; // Level 3 is at index 2 (0-indexed)
var totalButtons = 5;
var totalButtonWidth = totalButtons * 270 + (totalButtons - 1) * buttonSpacing; // 270 is approximate button width after scaling
var startX = 2048 / 2 - totalButtonWidth / 2 + 700 - 25;
for (var levelNum = 1; levelNum <= 5; levelNum++) {
var levelBtn = new Container();
var levelBtnBg = levelBtn.attachAsset('cardMatch', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.9,
scaleY: 0.75
});
var levelBtnText = new Text2('Level ' + levelNum, {
size: 50,
fill: 0xFFFFFF
});
levelBtnText.anchor.set(0.5, 0.5);
levelBtnText.x = 0;
levelBtnText.y = 0;
levelBtn.addChild(levelBtnText);
levelBtn.levelNum = levelNum;
levelBtn.x = startX + (levelNum - 1) * buttonSpacing;
levelBtn.y = levelButtonY;
game.addChild(levelBtn);
levelButtons.push(levelBtn);
levelBtn.down = function (btnLevel) {
return function (x, y, obj) {
level = btnLevel;
// Update visual feedback for selected level
for (var updateBtn = 0; updateBtn < levelButtons.length; updateBtn++) {
var btnBg = levelButtons[updateBtn].children[0];
if (levelButtons[updateBtn].levelNum === btnLevel) {
tween(btnBg, {
tint: 0xFFCC00
}, {
duration: 300,
easing: tween.easeOut
});
} else {
tween(btnBg, {
tint: 0xFFFFFF
}, {
duration: 300,
easing: tween.easeOut
});
}
}
};
}(levelNum);
}
var startBtn = new Container();
var startBtnBg = startBtn.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
var startBtnText = new Text2('Start Game', {
size: 60,
fill: 0xFFFFFF
});
startBtnText.anchor.set(0.5, 0.5);
startBtn.addChild(startBtnText);
startBtn.x = 2048 / 2;
startBtn.y = 2732 / 2 + 150;
game.addChild(startBtn);
// Timer update
var timerInterval;
function startTimer() {
gameStartTime = Date.now();
timerInterval = LK.setInterval(function () {
var elapsed = Math.floor((Date.now() - gameStartTime) / 1000);
timerText.setText('Time: ' + elapsed + 's');
}, 1000);
}
// Initialize the game board
function initializeBoard() {
// Clear existing cards
for (var i = 0; i < cards.length; i++) {
cards[i].destroy();
}
cards = [];
flippedCards = [];
pairsFound = 0;
moves = 0;
processingMatch = false;
gameActive = true;
movesText.setText('Moves: 0');
// Update level text display
levelText.setText('Level: ' + level);
// Show HUD elements when game starts
movesText.visible = true;
levelText.visible = true;
timerText.visible = true;
// Set level-based grid size
if (level === 1) {
gridWidth = 3;
gridHeight = 3;
} else if (level === 2) {
gridWidth = 3;
gridHeight = 4;
} else if (level === 3) {
gridWidth = 4;
gridHeight = 4;
} else if (level === 4) {
gridWidth = 4;
gridHeight = 5;
} else if (level >= 5) {
gridWidth = 5;
gridHeight = 5;
}
// Calculate total cards accounting for skipped center card on level 1 and level 5
var totalCards = gridWidth * gridHeight;
if (level === 1 || level === 5) {
totalCards = totalCards - 1;
}
totalPairs = totalCards / 2;
// Create cards and assign pairs
var pairIds = [];
if (level >= 5) {
// Level 5: Create 12 pairs (A-L) each appearing exactly twice to fill 24 cards
// 12 pairs × 2 = 24 cards with perfect pairing
for (var p = 0; p < 12; p++) {
var pairLetter = String.fromCharCode(65 + p);
pairIds.push(pairLetter);
pairIds.push(pairLetter);
}
} else {
// Levels 1-4: Create exact pairs needed without repetition
for (var p = 0; p < totalPairs; p++) {
var pairLetter = String.fromCharCode(65 + p);
pairIds.push(pairLetter);
pairIds.push(pairLetter);
}
}
// Shuffle pairs
for (var s = pairIds.length - 1; s > 0; s--) {
var j = Math.floor(Math.random() * (s + 1));
var temp = pairIds[s];
pairIds[s] = pairIds[j];
pairIds[j] = temp;
}
// Determine the grid layout positioning
var gridTotalWidth = gridWidth * cardWidth + (gridWidth - 1) * cardSpacing;
var gridTotalHeight = gridHeight * cardHeight + (gridHeight - 1) * cardSpacing;
var startX = (2048 - gridTotalWidth) / 2;
var startY = (2732 - gridTotalHeight) / 2 + (level >= 5 ? 100 : 0);
// Move level 4 cards down by 123 units
if (level === 4) {
startY += 123;
}
// Create and position the cards
var cardIndex = 0;
for (var row = 0; row < gridHeight; row++) {
for (var col = 0; col < gridWidth; col++) {
// Skip center card for level 1 and level 5
if (level === 1 && row === 1 && col === 1 || level === 5 && row === 2 && col === 2) {
continue;
}
var x = startX + col * (cardWidth + cardSpacing) + cardWidth / 2;
var y = startY + row * (cardHeight + cardSpacing) + cardHeight / 2;
var card = new Card(cardIndex, pairIds[cardIndex]);
card.x = x;
card.y = y;
cards.push(card);
game.addChild(card);
cardIndex++;
}
}
// Start the timer
startTimer();
// Play background music
LK.playMusic('bgmusic');
}
// Check for matching cards
function checkForMatch(card) {
flippedCards.push(card);
if (flippedCards.length === 2) {
processingMatch = true;
moves++;
movesText.setText('Moves: ' + moves);
var card1 = flippedCards[0];
var card2 = flippedCards[1];
if (card1.pairId === card2.pairId) {
// Match found
LK.setTimeout(function () {
LK.getSound('match').play();
card1.setMatched();
card2.setMatched();
flippedCards = [];
processingMatch = false;
// Increment pairs found
pairsFound++;
// Check for win condition
if (pairsFound === totalPairs) {
gameWon();
}
}, 500);
} else {
// No match
LK.setTimeout(function () {
LK.getSound('nomatch').play();
card1.flipBack();
card2.flipBack();
flippedCards = [];
processingMatch = false;
}, 1000);
}
}
}
// Handle game win
function gameWon() {
gameActive = false;
// Calculate score based on moves and time
var timeElapsed = Math.floor((Date.now() - gameStartTime) / 1000);
LK.clearInterval(timerInterval);
// Calculate score (fewer moves and less time = higher score)
var baseScore = 1000;
var movePenalty = moves * 10;
var timePenalty = timeElapsed * 2;
var score = Math.max(100, baseScore - movePenalty - timePenalty);
// Update best score
if (score > storage.bestScore) {
storage.bestScore = score;
}
// Set the score
LK.setScore(score);
// Play win sound
LK.getSound('win').play();
// Show win message
LK.setTimeout(function () {
// Hide HUD elements
movesText.visible = false;
levelText.visible = false;
timerText.visible = false;
// Level up
level++;
storage.level = level;
// Show you win screen
LK.showYouWin();
// Load the next level after a short delay to ensure transition
LK.setTimeout(function () {
initializeBoard();
gameActive = true; // Reactivate the game
startTimer(); // Restart the timer for the new level
}, 2000); // Delay to allow the win screen to show
}, 1500);
}
// Start button interaction
startBtn.down = function (x, y, obj) {
// Remove level selector buttons
for (var lb = 0; lb < levelButtons.length; lb++) {
game.removeChild(levelButtons[lb]);
}
game.removeChild(startBtn);
initializeBoard();
};
// Handle game update
game.update = function () {
// Nothing needed here as the game logic is event-driven
}; ===================================================================
--- original.js
+++ change.js
@@ -157,9 +157,9 @@
var level = 1;
var totalPairs = gridWidth * gridHeight / 2;
var gameStartTime;
// UI Elements
-var titleText = new Text2("St. Patrick's Day Match Game", {
+var titleText = new Text2("Card Game Menu", {
size: 80,
fill: 0xFFA500,
fontWeight: 'bolder'
});
yellow rectangle button
Leprechaun on a white papercard with rounded corners, front view.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Golden shamrock pendant. High contrast
3 leaf clover in a white paper card with rounded corners, front view.
Lucky star in a white paper-card with rounded corners, front view.. In-Game asset. 2d. No shadows
Green Hearth in a white paper-card with rounded corners, front view.. In-Game asset. 2d. High contrast. No shadows
Green ribbon with shamrock in a white paper-card with rounded corners, front view..