User prompt
On the start screen, I also want to let players choose the number of rounds to be played (1, 3, or 5 rounds) while selecting the target limit. I want to increase the size of the cards.
Code edit (1 edits merged)
Please save this source code
User prompt
Over the Limit
Initial prompt
I want to create a card game where each card has a numerical value, and if the total value exceeds a predetermined amount, one side loses. For example, I have the cards 4, 6, 7, and 9 in my hand. The opponent has the cards 3, 5, 6, and 8. I play the 4 and 6 cards. The opponent plays the 3 and 5 cards. Whoever exceeds 30 loses. If I play the 7, the opponent loses. Each player can have 4 cards in their hand, and the card numbers should range from 1 to 10. There should be 5 copies of each number, for a total of 50 cards, and there should be two additional 0 cards. At the beginning, I want the players to choose the maximum total (the limit not to be exceeded) on a screen; there should be 3 options: 30, 50, or 80. The game continues until the chosen number is exceeded.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Card = Container.expand(function (value) { var self = Container.call(this); self.value = value || 0; self.isSelected = false; var cardGraphics = self.attachAsset('cardFront', { anchorX: 0.5, anchorY: 0.5 }); var cardText = new Text2(self.value.toString(), { size: 80, fill: 0x2C3E50 }); cardText.anchor.set(0.5, 0.5); self.addChild(cardText); self.setSelected = function (selected) { self.isSelected = selected; if (selected) { cardGraphics.tint = 0xf1c40f; self.y -= 20; } else { cardGraphics.tint = 0xffffff; self.y += 20; } }; self.down = function (x, y, obj) { if (currentGameState === 'playing' && currentPlayer === 0) { self.setSelected(!self.isSelected); } }; return self; }); var LimitButton = Container.expand(function (limit) { var self = Container.call(this); self.limit = limit; self.isSelected = false; var buttonGraphics = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(limit.toString(), { size: 40, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.setSelected = function (selected) { self.isSelected = selected; buttonGraphics.removeChild(buttonGraphics.children[0]); if (selected) { buttonGraphics.addChild(LK.getAsset('selectedButton', { anchorX: 0.5, anchorY: 0.5 })); } else { buttonGraphics.addChild(LK.getAsset('button', { anchorX: 0.5, anchorY: 0.5 })); } }; self.down = function (x, y, obj) { if (currentGameState === 'setup') { selectLimit(self.limit); } }; return self; }); var RoundButton = Container.expand(function (rounds) { var self = Container.call(this); self.rounds = rounds; self.isSelected = false; var buttonGraphics = self.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(rounds + ' Round' + (rounds > 1 ? 's' : ''), { size: 35, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.setSelected = function (selected) { self.isSelected = selected; buttonGraphics.removeChild(buttonGraphics.children[0]); if (selected) { buttonGraphics.addChild(LK.getAsset('selectedButton', { anchorX: 0.5, anchorY: 0.5 })); } else { buttonGraphics.addChild(LK.getAsset('button', { anchorX: 0.5, anchorY: 0.5 })); } }; self.down = function (x, y, obj) { if (currentGameState === 'setup') { selectRounds(self.rounds); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x27ae60 }); /**** * Game Code ****/ // Game state variables var currentGameState = 'setup'; // 'setup', 'playing', 'gameOver' var selectedLimit = 0; var selectedRounds = 0; var maxRounds = 0; var currentTotal = 0; var currentPlayer = 0; // 0 = player, 1 = AI var playerHand = []; var aiHand = []; var deck = []; var playerScore = 0; var aiScore = 0; // UI elements var limitButtons = []; var roundButtons = []; var playAreaGraphics; var totalText; var limitText; var playerHandContainer; var aiHandContainer; var playButton; var statusText; var scoreText; // Initialize deck function initializeDeck() { deck = []; // Add 5 copies of cards 1-10 for (var i = 1; i <= 10; i++) { for (var j = 0; j < 5; j++) { deck.push(i); } } // Add 2 zero cards deck.push(0); deck.push(0); shuffleDeck(); } function shuffleDeck() { for (var i = deck.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = deck[i]; deck[i] = deck[j]; deck[j] = temp; } } function dealCard() { if (deck.length === 0) { initializeDeck(); } return deck.pop(); } function dealInitialHands() { playerHand = []; aiHand = []; for (var i = 0; i < 4; i++) { playerHand.push(dealCard()); aiHand.push(dealCard()); } } function createLimitSelection() { var limits = [30, 50, 80]; for (var i = 0; i < limits.length; i++) { var button = new LimitButton(limits[i]); button.x = 1024 + (i - 1) * 300; button.y = 1000; limitButtons.push(button); game.addChild(button); } var rounds = [1, 3, 5]; for (var i = 0; i < rounds.length; i++) { var roundButton = new RoundButton(rounds[i]); roundButton.x = 1024 + (i - 1) * 300; roundButton.y = 1300; roundButtons.push(roundButton); game.addChild(roundButton); } var limitInstructionText = new Text2('Choose Target Limit', { size: 70, fill: 0xFFFFFF }); limitInstructionText.anchor.set(0.5, 0.5); limitInstructionText.x = 1024; limitInstructionText.y = 850; game.addChild(limitInstructionText); var roundInstructionText = new Text2('Choose Number of Rounds', { size: 70, fill: 0xFFFFFF }); roundInstructionText.anchor.set(0.5, 0.5); roundInstructionText.x = 1024; roundInstructionText.y = 1150; game.addChild(roundInstructionText); } function selectRounds(rounds) { selectedRounds = rounds; maxRounds = rounds; for (var i = 0; i < roundButtons.length; i++) { roundButtons[i].setSelected(roundButtons[i].rounds === rounds); } checkStartGameReady(); } function selectLimit(limit) { selectedLimit = limit; for (var i = 0; i < limitButtons.length; i++) { limitButtons[i].setSelected(limitButtons[i].limit === limit); } checkStartGameReady(); } function checkStartGameReady() { if (selectedLimit > 0 && selectedRounds > 0) { if (!playButton) { playButton = new Container(); var playGraphics = playButton.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); var playText = new Text2('Start Game', { size: 40, fill: 0xFFFFFF }); playText.anchor.set(0.5, 0.5); playButton.addChild(playText); playButton.x = 1024; playButton.y = 1500; playButton.down = function (x, y, obj) { startGame(); }; game.addChild(playButton); } } } function startGame() { currentGameState = 'playing'; currentTotal = 0; currentPlayer = 0; // Clear setup UI for (var i = 0; i < limitButtons.length; i++) { limitButtons[i].destroy(); } limitButtons = []; for (var i = 0; i < roundButtons.length; i++) { roundButtons[i].destroy(); } roundButtons = []; if (playButton) { playButton.destroy(); playButton = null; } // Initialize game initializeDeck(); dealInitialHands(); createGameUI(); updateDisplay(); } function createGameUI() { // Play area playAreaGraphics = game.attachAsset('playArea', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 }); // Total display totalText = new Text2('Total: 0', { size: 60, fill: 0xFFFFFF }); totalText.anchor.set(0.5, 0.5); totalText.x = 1024; totalText.y = 1366; game.addChild(totalText); // Limit display limitText = new Text2('Limit: ' + selectedLimit, { size: 40, fill: 0xFFFFFF }); limitText.anchor.set(0.5, 0.5); limitText.x = 1024; limitText.y = 1300; game.addChild(limitText); // Player hand container playerHandContainer = new Container(); playerHandContainer.x = 1024; playerHandContainer.y = 2200; game.addChild(playerHandContainer); // AI hand container aiHandContainer = new Container(); aiHandContainer.x = 1024; aiHandContainer.y = 500; game.addChild(aiHandContainer); // Status text statusText = new Text2('Your Turn - Select cards and tap Play', { size: 40, fill: 0xFFFFFF }); statusText.anchor.set(0.5, 0.5); statusText.x = 1024; statusText.y = 1800; game.addChild(statusText); // Score display scoreText = new Text2('You: ' + playerScore + ' - AI: ' + aiScore, { size: 40, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0.5); scoreText.x = 1024; scoreText.y = 200; game.addChild(scoreText); // Play cards button var playCardsButton = new Container(); var playCardsGraphics = playCardsButton.attachAsset('button', { anchorX: 0.5, anchorY: 0.5 }); var playCardsText = new Text2('Play Cards', { size: 40, fill: 0xFFFFFF }); playCardsText.anchor.set(0.5, 0.5); playCardsButton.addChild(playCardsText); playCardsButton.x = 1024; playCardsButton.y = 1950; playCardsButton.down = function (x, y, obj) { if (currentPlayer === 0) { playSelectedCards(); } }; game.addChild(playCardsButton); } function updateDisplay() { totalText.setText('Total: ' + currentTotal); scoreText.setText('You: ' + playerScore + ' - AI: ' + aiScore); // Update player hand playerHandContainer.removeChildren(); for (var i = 0; i < playerHand.length; i++) { var card = new Card(playerHand[i]); card.x = (i - 1.5) * 200; playerHandContainer.addChild(card); } // Update AI hand (show card backs) aiHandContainer.removeChildren(); for (var i = 0; i < aiHand.length; i++) { var cardBack = aiHandContainer.attachAsset('cardBack', { anchorX: 0.5, anchorY: 0.5, x: (i - 1.5) * 200 }); } // Update status if (currentPlayer === 0) { statusText.setText('Your Turn - Select cards and tap Play'); } else { statusText.setText('AI is thinking...'); } } function playSelectedCards() { var selectedCards = []; var selectedIndices = []; for (var i = 0; i < playerHandContainer.children.length; i++) { var card = playerHandContainer.children[i]; if (card.isSelected) { selectedCards.push(card.value); selectedIndices.push(i); } } if (selectedCards.length === 0) { return; } // Calculate total of selected cards var cardTotal = 0; for (var i = 0; i < selectedCards.length; i++) { cardTotal += selectedCards[i]; } currentTotal += cardTotal; LK.getSound('cardPlay').play(); // Remove played cards from hand for (var i = selectedIndices.length - 1; i >= 0; i--) { playerHand.splice(selectedIndices[i], 1); } // Replenish hand while (playerHand.length < 4 && deck.length > 0) { playerHand.push(dealCard()); } // Check if player exceeded limit if (currentTotal > selectedLimit) { endRound(false); return; } currentPlayer = 1; updateDisplay(); // AI turn after delay LK.setTimeout(function () { aiTurn(); }, 1500); } function aiTurn() { // Simple AI strategy: play lowest safe card(s) var safeCards = []; var safeIndices = []; for (var i = 0; i < aiHand.length; i++) { if (currentTotal + aiHand[i] <= selectedLimit) { safeCards.push(aiHand[i]); safeIndices.push(i); } } if (safeCards.length === 0) { // AI must play and will lose var minCard = Math.min.apply(Math, aiHand); var minIndex = aiHand.indexOf(minCard); currentTotal += minCard; aiHand.splice(minIndex, 1); endRound(true); return; } // Play the lowest safe card var minSafe = Math.min.apply(Math, safeCards); var playIndex = aiHand.indexOf(minSafe); currentTotal += minSafe; aiHand.splice(playIndex, 1); // Replenish AI hand while (aiHand.length < 4 && deck.length > 0) { aiHand.push(dealCard()); } LK.getSound('cardPlay').play(); currentPlayer = 0; updateDisplay(); } function endRound(playerWon) { LK.getSound('gameOver').play(); if (playerWon) { playerScore++; statusText.setText('You Won! AI went over the limit.'); } else { aiScore++; statusText.setText('You Lost! You went over the limit.'); } updateDisplay(); // Check for game end var winThreshold = Math.ceil(maxRounds / 2); if (playerScore >= winThreshold) { statusText.setText('Game Over! You Win!'); LK.showYouWin(); return; } else if (aiScore >= winThreshold) { statusText.setText('Game Over! AI Wins!'); LK.showGameOver(); return; } // Start new round after delay LK.setTimeout(function () { currentTotal = 0; currentPlayer = 0; dealInitialHands(); updateDisplay(); }, 3000); } // Initialize game createLimitSelection(); game.update = function () { // Game loop updates };
===================================================================
--- original.js
+++ change.js
@@ -14,9 +14,9 @@
anchorX: 0.5,
anchorY: 0.5
});
var cardText = new Text2(self.value.toString(), {
- size: 60,
+ size: 80,
fill: 0x2C3E50
});
cardText.anchor.set(0.5, 0.5);
self.addChild(cardText);
@@ -72,8 +72,44 @@
}
};
return self;
});
+var RoundButton = Container.expand(function (rounds) {
+ var self = Container.call(this);
+ self.rounds = rounds;
+ self.isSelected = false;
+ var buttonGraphics = self.attachAsset('button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var buttonText = new Text2(rounds + ' Round' + (rounds > 1 ? 's' : ''), {
+ size: 35,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ self.addChild(buttonText);
+ self.setSelected = function (selected) {
+ self.isSelected = selected;
+ buttonGraphics.removeChild(buttonGraphics.children[0]);
+ if (selected) {
+ buttonGraphics.addChild(LK.getAsset('selectedButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ } else {
+ buttonGraphics.addChild(LK.getAsset('button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (currentGameState === 'setup') {
+ selectRounds(self.rounds);
+ }
+ };
+ return self;
+});
/****
* Initialize Game
****/
@@ -86,8 +122,10 @@
****/
// Game state variables
var currentGameState = 'setup'; // 'setup', 'playing', 'gameOver'
var selectedLimit = 0;
+var selectedRounds = 0;
+var maxRounds = 0;
var currentTotal = 0;
var currentPlayer = 0; // 0 = player, 1 = AI
var playerHand = [];
var aiHand = [];
@@ -95,8 +133,9 @@
var playerScore = 0;
var aiScore = 0;
// UI elements
var limitButtons = [];
+var roundButtons = [];
var playAreaGraphics;
var totalText;
var limitText;
var playerHandContainer;
@@ -144,44 +183,73 @@
var limits = [30, 50, 80];
for (var i = 0; i < limits.length; i++) {
var button = new LimitButton(limits[i]);
button.x = 1024 + (i - 1) * 300;
- button.y = 1200;
+ button.y = 1000;
limitButtons.push(button);
game.addChild(button);
}
- var instructionText = new Text2('Choose Target Limit', {
- size: 80,
+ var rounds = [1, 3, 5];
+ for (var i = 0; i < rounds.length; i++) {
+ var roundButton = new RoundButton(rounds[i]);
+ roundButton.x = 1024 + (i - 1) * 300;
+ roundButton.y = 1300;
+ roundButtons.push(roundButton);
+ game.addChild(roundButton);
+ }
+ var limitInstructionText = new Text2('Choose Target Limit', {
+ size: 70,
fill: 0xFFFFFF
});
- instructionText.anchor.set(0.5, 0.5);
- instructionText.x = 1024;
- instructionText.y = 1000;
- game.addChild(instructionText);
+ limitInstructionText.anchor.set(0.5, 0.5);
+ limitInstructionText.x = 1024;
+ limitInstructionText.y = 850;
+ game.addChild(limitInstructionText);
+ var roundInstructionText = new Text2('Choose Number of Rounds', {
+ size: 70,
+ fill: 0xFFFFFF
+ });
+ roundInstructionText.anchor.set(0.5, 0.5);
+ roundInstructionText.x = 1024;
+ roundInstructionText.y = 1150;
+ game.addChild(roundInstructionText);
}
+function selectRounds(rounds) {
+ selectedRounds = rounds;
+ maxRounds = rounds;
+ for (var i = 0; i < roundButtons.length; i++) {
+ roundButtons[i].setSelected(roundButtons[i].rounds === rounds);
+ }
+ checkStartGameReady();
+}
function selectLimit(limit) {
selectedLimit = limit;
for (var i = 0; i < limitButtons.length; i++) {
limitButtons[i].setSelected(limitButtons[i].limit === limit);
}
- if (!playButton) {
- playButton = new Container();
- var playGraphics = playButton.attachAsset('button', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- var playText = new Text2('Start Game', {
- size: 40,
- fill: 0xFFFFFF
- });
- playText.anchor.set(0.5, 0.5);
- playButton.addChild(playText);
- playButton.x = 1024;
- playButton.y = 1400;
- playButton.down = function (x, y, obj) {
- startGame();
- };
- game.addChild(playButton);
+ checkStartGameReady();
+}
+function checkStartGameReady() {
+ if (selectedLimit > 0 && selectedRounds > 0) {
+ if (!playButton) {
+ playButton = new Container();
+ var playGraphics = playButton.attachAsset('button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var playText = new Text2('Start Game', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ playText.anchor.set(0.5, 0.5);
+ playButton.addChild(playText);
+ playButton.x = 1024;
+ playButton.y = 1500;
+ playButton.down = function (x, y, obj) {
+ startGame();
+ };
+ game.addChild(playButton);
+ }
}
}
function startGame() {
currentGameState = 'playing';
@@ -191,8 +259,12 @@
for (var i = 0; i < limitButtons.length; i++) {
limitButtons[i].destroy();
}
limitButtons = [];
+ for (var i = 0; i < roundButtons.length; i++) {
+ roundButtons[i].destroy();
+ }
+ roundButtons = [];
if (playButton) {
playButton.destroy();
playButton = null;
}
@@ -283,18 +355,18 @@
// Update player hand
playerHandContainer.removeChildren();
for (var i = 0; i < playerHand.length; i++) {
var card = new Card(playerHand[i]);
- card.x = (i - 1.5) * 150;
+ card.x = (i - 1.5) * 200;
playerHandContainer.addChild(card);
}
// Update AI hand (show card backs)
aiHandContainer.removeChildren();
for (var i = 0; i < aiHand.length; i++) {
var cardBack = aiHandContainer.attachAsset('cardBack', {
anchorX: 0.5,
anchorY: 0.5,
- x: (i - 1.5) * 150
+ x: (i - 1.5) * 200
});
}
// Update status
if (currentPlayer === 0) {
@@ -385,13 +457,14 @@
statusText.setText('You Lost! You went over the limit.');
}
updateDisplay();
// Check for game end
- if (playerScore >= 3) {
+ var winThreshold = Math.ceil(maxRounds / 2);
+ if (playerScore >= winThreshold) {
statusText.setText('Game Over! You Win!');
LK.showYouWin();
return;
- } else if (aiScore >= 3) {
+ } else if (aiScore >= winThreshold) {
statusText.setText('Game Over! AI Wins!');
LK.showGameOver();
return;
}
Create a 3D button with rounded corners, and make sure it appears in a rectangular shape.. In-Game asset. 2d. High contrast. No shadows
A thought bubble or a speech bubble (as used in animations) with a slightly 3D appearance, designed as an in-game asset, 2D, with shadows. It should not look like a cloud; the outline should be clean and defined, and the shape should be regular—but not perfectly oval or geometric.
The arrow indicator could have a more authentic look—for example, a stone texture covered with moss, with slightly faded colors.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 0, with a white border around it and a gray background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 2, with a white border around it and a blue background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 1, with a white border around it and a yellow background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 3, with a white border around it and a green background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 4, with a white border around it and an orange background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 5, with a white border around it and a purple background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 6, with a white border around it and a turquoise background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 7, with a white border around it and a terracotta background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 8, with a white border around it and a burgundy background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 9, with a white border around it and a red background.. In-Game asset. 2d. High contrast. No shadows
Rectangular card numbered 10, with a white border around it and a dark background.. In-Game asset. 2d. High contrast. No shadows
A rectangular, semi-transparent frame.. In-Game asset. 2d. High contrast. No shadows
The back of the playing card will not have traditional playing card symbols and will include 3D visuals.. In-Game asset. 3d
The picnic blanket in the image should look more like an anime-style (3D) drawing, without changing its colors.
Add small tears in two places and a burn mark in one place.
I want you to write the word “CardiT” in 3D, using vibrant colors. The style should be like animation, but not childish.. In-Game asset. High contrast. No shadows. 3d. Anime