User prompt
arka plana koyu yeşil bir arka plan istiyorun
User prompt
every round make the shuffling little bit faster
User prompt
ok lets do it
User prompt
ok its looks good, but its a litte bit easey, to make it harder, shuffle the correct card, more than the other cards
User prompt
make 9 cards not 10, becouse of the screen it cannot placed, so make 3 rows of cards, starting with first row when the player reach round 3 so the next card goese to second row and it will be shuffled, and when the player reach the round 6 so the 7th card goes to thrid row
User prompt
please start with 2 cards, just simple, and after when the correct card will be picked, so add a new card, and make this untill round 10. that meens when the player comes to round 10, we must have 10 cards
Code edit (1 edits merged)
Please save this source code
User prompt
Three Card Shuffle
Initial prompt
make me a game like 3 card monte, but i wana play this game in a browser
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Card class: represents a single card in the 3 card shuffle game var Card = Container.expand(function () { var self = Container.call(this); // Card states: 'faceup', 'facedown', 'revealed' self.state = 'facedown'; self.isPrize = false; self.index = 0; // 0,1,2 for left, center, right // Card dimensions var cardWidth = 350; var cardHeight = 500; // Face down color var backColor = 0x444444; // Face up color var faceColor = 0xffffff; // Prize color var prizeColor = 0xffd700; // Card back (facedown) var back = self.attachAsset('cardBack', { width: cardWidth, height: cardHeight, color: backColor, shape: 'box', anchorX: 0.5, anchorY: 1 }); // Card face (faceup) var face = self.attachAsset('cardFace', { width: cardWidth, height: cardHeight, color: faceColor, shape: 'box', anchorX: 0.5, anchorY: 1 }); face.visible = false; // Prize indicator (only visible if isPrize and faceup) var prize = self.attachAsset('prizeCircle', { width: 120, height: 120, color: prizeColor, shape: 'ellipse', anchorX: 0.5, anchorY: 0.5, x: 0, y: -cardHeight / 2 }); prize.visible = false; // For tap feedback var highlight = self.attachAsset('highlight', { width: cardWidth + 20, height: cardHeight + 20, color: 0x00ff00, shape: 'box', anchorX: 0.5, anchorY: 1 }); highlight.alpha = 0; highlight.visible = true; // Card label (for debugging or future use) // var label = new Text2('', {size: 60, fill: "#222"}); // label.anchor.set(0.5, 0.5); // label.x = 0; // label.y = -cardHeight / 2; // self.addChild(label); // Set card state: 'faceup', 'facedown', 'revealed' self.setState = function (state) { self.state = state; if (state === 'faceup') { face.visible = true; back.visible = false; prize.visible = self.isPrize; } else if (state === 'facedown') { face.visible = false; back.visible = true; prize.visible = false; } else if (state === 'revealed') { face.visible = true; back.visible = false; prize.visible = self.isPrize; } }; // Show highlight (for tap feedback) self.flashHighlight = function () { highlight.alpha = 0.5; tween(highlight, { alpha: 0 }, { duration: 400, easing: tween.linear }); }; // Card tap event self.down = function (x, y, obj) { if (typeof onCardTap === 'function') { onCardTap(self); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0a1a2f }); /**** * Game Code ****/ // Game constants var NUM_CARDS = 3; var CARD_SPACING = 420; var CARD_Y = 1800; var CARD_START_X = 2048 / 2 - CARD_SPACING; var cardWidth = 350; var cardHeight = 500; // Game state var cards = []; var prizeIndex = 0; var round = 1; var shuffling = false; var canPick = false; var score = 0; var shuffleCount = 3; var shuffleSpeed = 500; var maxRounds = 10; // GUI elements var scoreTxt = new Text2('Score: 0', { size: 110, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var roundTxt = new Text2('Round 1', { size: 80, fill: "#fff" }); roundTxt.anchor.set(0.5, 0); LK.gui.top.addChild(roundTxt); roundTxt.y = 120; // Message text (centered) var messageTxt = new Text2('', { size: 120, fill: "#fff" }); messageTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(messageTxt); messageTxt.visible = false; // Helper: show message in center for ms milliseconds function showMessage(msg, ms) { messageTxt.setText(msg); messageTxt.visible = true; if (ms) { LK.setTimeout(function () { messageTxt.visible = false; }, ms); } } // Helper: update score and round display function updateGUI() { scoreTxt.setText('Score: ' + score); roundTxt.setText('Round ' + round); } // Helper: reset all cards to facedown function allCardsFacedown() { for (var i = 0; i < cards.length; i++) { cards[i].setState('facedown'); } } // Helper: flip all cards faceup (show prize) function allCardsFaceup() { for (var i = 0; i < cards.length; i++) { cards[i].setState('faceup'); } } // Helper: reveal all cards (show which had prize) function revealAllCards() { for (var i = 0; i < cards.length; i++) { cards[i].setState('revealed'); } } // Helper: get card positions for indices 0,1,2 function getCardPos(idx) { return { x: CARD_START_X + idx * CARD_SPACING, y: CARD_Y }; } // Helper: shuffle array in place function shuffleArray(arr) { for (var i = arr.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } // Helper: animate swap between two cards function animateSwap(cardA, cardB, duration, onFinish) { var ax = cardA.x, ay = cardA.y; var bx = cardB.x, by = cardB.y; tween(cardA, { x: bx, y: by }, { duration: duration, easing: tween.cubicInOut }); tween(cardB, { x: ax, y: ay }, { duration: duration, easing: tween.cubicInOut, onFinish: onFinish }); } // Helper: perform a shuffle sequence (array of swaps) function performShuffleSequence(swaps, idx, onFinish) { if (idx >= swaps.length) { if (onFinish) onFinish(); return; } var pair = swaps[idx]; animateSwap(cards[pair[0]], cards[pair[1]], shuffleSpeed, function () { // Swap card objects in array var temp = cards[pair[0]]; cards[pair[0]] = cards[pair[1]]; cards[pair[1]] = temp; // Update indices cards[0].index = 0; cards[1].index = 1; cards[2].index = 2; performShuffleSequence(swaps, idx + 1, onFinish); }); } // Helper: generate a random shuffle sequence (array of [i,j] swaps) function generateShuffleSequence(count) { var swaps = []; for (var i = 0; i < count; i++) { // Pick two distinct indices var a = Math.floor(Math.random() * NUM_CARDS); var b; do { b = Math.floor(Math.random() * NUM_CARDS); } while (b === a); swaps.push([a, b]); } return swaps; } // Start a new round function startRound() { shuffling = false; canPick = false; updateGUI(); // Place cards in initial positions for (var i = 0; i < NUM_CARDS; i++) { var pos = getCardPos(i); cards[i].x = pos.x; cards[i].y = pos.y; cards[i].index = i; cards[i].isPrize = false; cards[i].setState('facedown'); } // Randomly assign prize prizeIndex = Math.floor(Math.random() * NUM_CARDS); cards[prizeIndex].isPrize = true; // Show all cards faceup for 1s allCardsFaceup(); showMessage('Find the Prize!', 1000); LK.setTimeout(function () { // Flip all cards facedown allCardsFacedown(); LK.setTimeout(function () { // Start shuffling shuffleCount = 3 + round; // Increase shuffle count per round shuffleSpeed = Math.max(220, 600 - round * 40); // Faster per round var swaps = generateShuffleSequence(shuffleCount); shuffling = true; performShuffleSequence(swaps, 0, function () { shuffling = false; canPick = true; showMessage('Pick a Card!', 800); }); }, 500); }, 1000); } // Card tap handler function onCardTap(card) { if (!canPick || shuffling) return; canPick = false; card.flashHighlight(); // Reveal all cards revealAllCards(); if (card.isPrize) { score += 1; updateGUI(); showMessage('Correct!', 900); LK.effects.flashObject(card, 0x00ff00, 600); LK.setTimeout(function () { nextRound(); }, 1100); } else { showMessage('Wrong!', 1200); LK.effects.flashObject(card, 0xff0000, 600); LK.setTimeout(function () { // Show game over LK.showGameOver(); }, 1300); } } // Next round or win function nextRound() { round += 1; if (round > maxRounds) { showMessage('You Win!', 1500); LK.setTimeout(function () { LK.showYouWin(); }, 1700); } else { startRound(); } } // --- Game setup --- // Create cards for (var i = 0; i < NUM_CARDS; i++) { var card = new Card(); var pos = getCardPos(i); card.x = pos.x; card.y = pos.y; card.index = i; card.setState('facedown'); cards.push(card); game.addChild(card); } // Prevent cards from being placed in top left 100x100 // (Cards are at y=1800, so this is always satisfied) // Start first round after short delay LK.setTimeout(function () { startRound(); }, 600); // --- Game update loop (not used for logic, but could be used for future animations) --- game.update = function () { // No per-frame logic needed for MVP };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,356 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Card class: represents a single card in the 3 card shuffle game
+var Card = Container.expand(function () {
+ var self = Container.call(this);
+ // Card states: 'faceup', 'facedown', 'revealed'
+ self.state = 'facedown';
+ self.isPrize = false;
+ self.index = 0; // 0,1,2 for left, center, right
+ // Card dimensions
+ var cardWidth = 350;
+ var cardHeight = 500;
+ // Face down color
+ var backColor = 0x444444;
+ // Face up color
+ var faceColor = 0xffffff;
+ // Prize color
+ var prizeColor = 0xffd700;
+ // Card back (facedown)
+ var back = self.attachAsset('cardBack', {
+ width: cardWidth,
+ height: cardHeight,
+ color: backColor,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Card face (faceup)
+ var face = self.attachAsset('cardFace', {
+ width: cardWidth,
+ height: cardHeight,
+ color: faceColor,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ face.visible = false;
+ // Prize indicator (only visible if isPrize and faceup)
+ var prize = self.attachAsset('prizeCircle', {
+ width: 120,
+ height: 120,
+ color: prizeColor,
+ shape: 'ellipse',
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: -cardHeight / 2
+ });
+ prize.visible = false;
+ // For tap feedback
+ var highlight = self.attachAsset('highlight', {
+ width: cardWidth + 20,
+ height: cardHeight + 20,
+ color: 0x00ff00,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ highlight.alpha = 0;
+ highlight.visible = true;
+ // Card label (for debugging or future use)
+ // var label = new Text2('', {size: 60, fill: "#222"});
+ // label.anchor.set(0.5, 0.5);
+ // label.x = 0;
+ // label.y = -cardHeight / 2;
+ // self.addChild(label);
+ // Set card state: 'faceup', 'facedown', 'revealed'
+ self.setState = function (state) {
+ self.state = state;
+ if (state === 'faceup') {
+ face.visible = true;
+ back.visible = false;
+ prize.visible = self.isPrize;
+ } else if (state === 'facedown') {
+ face.visible = false;
+ back.visible = true;
+ prize.visible = false;
+ } else if (state === 'revealed') {
+ face.visible = true;
+ back.visible = false;
+ prize.visible = self.isPrize;
+ }
+ };
+ // Show highlight (for tap feedback)
+ self.flashHighlight = function () {
+ highlight.alpha = 0.5;
+ tween(highlight, {
+ alpha: 0
+ }, {
+ duration: 400,
+ easing: tween.linear
+ });
+ };
+ // Card tap event
+ self.down = function (x, y, obj) {
+ if (typeof onCardTap === 'function') {
+ onCardTap(self);
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x0a1a2f
+});
+
+/****
+* Game Code
+****/
+// Game constants
+var NUM_CARDS = 3;
+var CARD_SPACING = 420;
+var CARD_Y = 1800;
+var CARD_START_X = 2048 / 2 - CARD_SPACING;
+var cardWidth = 350;
+var cardHeight = 500;
+// Game state
+var cards = [];
+var prizeIndex = 0;
+var round = 1;
+var shuffling = false;
+var canPick = false;
+var score = 0;
+var shuffleCount = 3;
+var shuffleSpeed = 500;
+var maxRounds = 10;
+// GUI elements
+var scoreTxt = new Text2('Score: 0', {
+ size: 110,
+ fill: "#fff"
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var roundTxt = new Text2('Round 1', {
+ size: 80,
+ fill: "#fff"
+});
+roundTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(roundTxt);
+roundTxt.y = 120;
+// Message text (centered)
+var messageTxt = new Text2('', {
+ size: 120,
+ fill: "#fff"
+});
+messageTxt.anchor.set(0.5, 0.5);
+LK.gui.center.addChild(messageTxt);
+messageTxt.visible = false;
+// Helper: show message in center for ms milliseconds
+function showMessage(msg, ms) {
+ messageTxt.setText(msg);
+ messageTxt.visible = true;
+ if (ms) {
+ LK.setTimeout(function () {
+ messageTxt.visible = false;
+ }, ms);
+ }
+}
+// Helper: update score and round display
+function updateGUI() {
+ scoreTxt.setText('Score: ' + score);
+ roundTxt.setText('Round ' + round);
+}
+// Helper: reset all cards to facedown
+function allCardsFacedown() {
+ for (var i = 0; i < cards.length; i++) {
+ cards[i].setState('facedown');
+ }
+}
+// Helper: flip all cards faceup (show prize)
+function allCardsFaceup() {
+ for (var i = 0; i < cards.length; i++) {
+ cards[i].setState('faceup');
+ }
+}
+// Helper: reveal all cards (show which had prize)
+function revealAllCards() {
+ for (var i = 0; i < cards.length; i++) {
+ cards[i].setState('revealed');
+ }
+}
+// Helper: get card positions for indices 0,1,2
+function getCardPos(idx) {
+ return {
+ x: CARD_START_X + idx * CARD_SPACING,
+ y: CARD_Y
+ };
+}
+// Helper: shuffle array in place
+function shuffleArray(arr) {
+ for (var i = arr.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = arr[i];
+ arr[i] = arr[j];
+ arr[j] = temp;
+ }
+}
+// Helper: animate swap between two cards
+function animateSwap(cardA, cardB, duration, onFinish) {
+ var ax = cardA.x,
+ ay = cardA.y;
+ var bx = cardB.x,
+ by = cardB.y;
+ tween(cardA, {
+ x: bx,
+ y: by
+ }, {
+ duration: duration,
+ easing: tween.cubicInOut
+ });
+ tween(cardB, {
+ x: ax,
+ y: ay
+ }, {
+ duration: duration,
+ easing: tween.cubicInOut,
+ onFinish: onFinish
+ });
+}
+// Helper: perform a shuffle sequence (array of swaps)
+function performShuffleSequence(swaps, idx, onFinish) {
+ if (idx >= swaps.length) {
+ if (onFinish) onFinish();
+ return;
+ }
+ var pair = swaps[idx];
+ animateSwap(cards[pair[0]], cards[pair[1]], shuffleSpeed, function () {
+ // Swap card objects in array
+ var temp = cards[pair[0]];
+ cards[pair[0]] = cards[pair[1]];
+ cards[pair[1]] = temp;
+ // Update indices
+ cards[0].index = 0;
+ cards[1].index = 1;
+ cards[2].index = 2;
+ performShuffleSequence(swaps, idx + 1, onFinish);
+ });
+}
+// Helper: generate a random shuffle sequence (array of [i,j] swaps)
+function generateShuffleSequence(count) {
+ var swaps = [];
+ for (var i = 0; i < count; i++) {
+ // Pick two distinct indices
+ var a = Math.floor(Math.random() * NUM_CARDS);
+ var b;
+ do {
+ b = Math.floor(Math.random() * NUM_CARDS);
+ } while (b === a);
+ swaps.push([a, b]);
+ }
+ return swaps;
+}
+// Start a new round
+function startRound() {
+ shuffling = false;
+ canPick = false;
+ updateGUI();
+ // Place cards in initial positions
+ for (var i = 0; i < NUM_CARDS; i++) {
+ var pos = getCardPos(i);
+ cards[i].x = pos.x;
+ cards[i].y = pos.y;
+ cards[i].index = i;
+ cards[i].isPrize = false;
+ cards[i].setState('facedown');
+ }
+ // Randomly assign prize
+ prizeIndex = Math.floor(Math.random() * NUM_CARDS);
+ cards[prizeIndex].isPrize = true;
+ // Show all cards faceup for 1s
+ allCardsFaceup();
+ showMessage('Find the Prize!', 1000);
+ LK.setTimeout(function () {
+ // Flip all cards facedown
+ allCardsFacedown();
+ LK.setTimeout(function () {
+ // Start shuffling
+ shuffleCount = 3 + round; // Increase shuffle count per round
+ shuffleSpeed = Math.max(220, 600 - round * 40); // Faster per round
+ var swaps = generateShuffleSequence(shuffleCount);
+ shuffling = true;
+ performShuffleSequence(swaps, 0, function () {
+ shuffling = false;
+ canPick = true;
+ showMessage('Pick a Card!', 800);
+ });
+ }, 500);
+ }, 1000);
+}
+// Card tap handler
+function onCardTap(card) {
+ if (!canPick || shuffling) return;
+ canPick = false;
+ card.flashHighlight();
+ // Reveal all cards
+ revealAllCards();
+ if (card.isPrize) {
+ score += 1;
+ updateGUI();
+ showMessage('Correct!', 900);
+ LK.effects.flashObject(card, 0x00ff00, 600);
+ LK.setTimeout(function () {
+ nextRound();
+ }, 1100);
+ } else {
+ showMessage('Wrong!', 1200);
+ LK.effects.flashObject(card, 0xff0000, 600);
+ LK.setTimeout(function () {
+ // Show game over
+ LK.showGameOver();
+ }, 1300);
+ }
+}
+// Next round or win
+function nextRound() {
+ round += 1;
+ if (round > maxRounds) {
+ showMessage('You Win!', 1500);
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 1700);
+ } else {
+ startRound();
+ }
+}
+// --- Game setup ---
+// Create cards
+for (var i = 0; i < NUM_CARDS; i++) {
+ var card = new Card();
+ var pos = getCardPos(i);
+ card.x = pos.x;
+ card.y = pos.y;
+ card.index = i;
+ card.setState('facedown');
+ cards.push(card);
+ game.addChild(card);
+}
+// Prevent cards from being placed in top left 100x100
+// (Cards are at y=1800, so this is always satisfied)
+// Start first round after short delay
+LK.setTimeout(function () {
+ startRound();
+}, 600);
+// --- Game update loop (not used for logic, but could be used for future animations) ---
+game.update = function () {
+ // No per-frame logic needed for MVP
+};
\ No newline at end of file