User prompt
Remove the existing code that displays the winner text. Then, add code to display "Player Won" when the player wins, "Computer Won" when the computer wins, and "Draw" in case of a tie. The text color should be white.
User prompt
Display the player's score as "Player x/10" on the left and the computer's score as "Computer x/10" on the right.
User prompt
Change the score display to the format "x/10". The first to reach 10 points wins.
User prompt
Display the winner on the screen. In case of a tie, display "draw".
User prompt
Display the countdown numbers on the screen during the countdown.
User prompt
Change all text colors to white.
User prompt
Assign the Scissors asset to the computer’s "Scissors" choice as well.
User prompt
Assign the Paper asset to the computer’s "Paper" choice as well.
User prompt
Assign the Scissors asset to the "SCISSORS" button
User prompt
Assign the Paper asset to the "PAPER" button.
User prompt
Align the text vertically and horizontally so that it lines up perfectly with the Rock asset.
User prompt
Set the background color to black and the text color to white.
User prompt
Set the background color to black and the text color to white. Make the text bold and increase its font size by 20 points.
User prompt
increase font size by 20
User prompt
Increase the text size so it aligns well with the Rock asset, and shift the text slightly downward for better positioning.
User prompt
Set the background color to black and the text color to white. Make the text bold and increase its font size by 2 points.
User prompt
Add a theme selector in the top-right corner with two options: Light Mode and Dark Mode. In Light Mode, text should be black; in Dark Mode, text should be white. Switching themes should update the text colors accordingly.
User prompt
Add a countdown from 3 down to 0. After the countdown text disappears from the screen, display the computer’s choice and then show the winner on the screen.
User prompt
Change the background to a soothing color
User prompt
Also apply for computer
User prompt
Assign the asset named "Rock" to the Rock button.
User prompt
Show the 3-second countdown on the screen.
User prompt
Add a scoring system where the first to reach 10 points wins. In case of a tie, display "Draw" on the screen.
User prompt
After a 3-second countdown, reveal the computer's choice. Then display the winner on the screen as either "Player Won" or "Computer Won".
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // --- Rock Paper Scissors Game Variables --- var choices = ['rock', 'paper', 'scissors']; var playerChoice = null; var computerChoice = null; var resultText = null; var playerScore = 0; var computerScore = 0; // --- Create GUI Score Display --- var scoreDisplay = new Text2('0/10 - 0/10', { size: 100, fill: 0xFFFFFF }); scoreDisplay.anchor.set(0.5, 0); LK.gui.top.addChild(scoreDisplay); // --- Create Result Text --- resultText = new Text2('', { size: 120, fill: 0xFFFFFF }); resultText.anchor.set(0.5, 0.5); LK.gui.center.addChild(resultText); // --- Create Choice Buttons --- var buttonSize = 350; var buttonSpacing = 120; var buttonY = 1800; var buttonStartX = (2048 - (buttonSize * 3 + buttonSpacing * 2)) / 2 + buttonSize / 2; var buttons = []; for (var i = 0; i < 3; i++) { var btn = new Container(); var btnAsset; if (choices[i] === 'rock') { btnAsset = LK.getAsset('Rock', { width: buttonSize, height: buttonSize, anchorX: 0.5, anchorY: 0.5 }); } else if (choices[i] === 'paper') { btnAsset = LK.getAsset('Paper', { width: buttonSize, height: buttonSize, anchorX: 0.5, anchorY: 0.5 }); } else { if (choices[i] === 'scissors') { btnAsset = LK.getAsset('Scissors', { width: buttonSize, height: buttonSize, anchorX: 0.5, anchorY: 0.5 }); } else { btnAsset = LK.getAsset('rps_' + choices[i], { width: buttonSize, height: buttonSize, anchorX: 0.5, anchorY: 0.5 }); } } btn.addChild(btnAsset); // Add label var label = new Text2(choices[i].toUpperCase(), { size: 70, fill: 0xFFFFFF }); label.anchor.set(0.5, 0); label.y = buttonSize / 2 + 20; btn.addChild(label); btn.x = buttonStartX + i * (buttonSize + buttonSpacing); btn.y = buttonY; btn.choice = choices[i]; btn.interactive = true; btn.buttonMode = true; buttons.push(btn); game.addChild(btn); } // --- Button Event Handlers --- for (var i = 0; i < buttons.length; i++) { (function (btn) { btn.down = function (x, y, obj) { if (playerChoice !== null) return; // Prevent double tap playerChoice = btn.choice; playRound(); }; })(buttons[i]); } // --- Play a Round --- function playRound() { // Prevent play if someone already won if (playerScore >= 10 || computerScore >= 10) { return; } // Computer random choice computerChoice = choices[Math.floor(Math.random() * 3)]; // Show countdown before revealing computer's choice and result var countdown = 3; resultText.setText(countdown.toString()); resultText.setStyle({ fill: 0xFFFFFF }); // Create a dedicated countdownText for displaying the countdown numbers if (!game.countdownText) { game.countdownText = new Text2('', { size: 220, fill: 0xFFFFFF }); game.countdownText.anchor.set(0.5, 0.5); LK.gui.center.addChild(game.countdownText); } game.countdownText.setText(countdown.toString()); game.countdownText.visible = true; var countdownInterval = null; function updateCountdown() { countdown--; if (countdown > 0) { game.countdownText.setText(countdown.toString()); game.countdownText.visible = true; } else if (countdown === 0) { game.countdownText.setText('0'); game.countdownText.visible = true; } else { // Countdown finished, hide countdown text if (countdownInterval) { LK.clearInterval(countdownInterval); countdownInterval = null; } game.countdownText.visible = false; resultText.setText(''); // Show computer's choice after countdown disappears showChoices(); // Show result after a short delay for dramatic effect LK.setTimeout(function () { var result = getResult(playerChoice, computerChoice); if (result === 'win') { playerScore++; resultText.setText(''); resultText.setStyle({ fill: 0xFFFFFF }); } else if (result === 'lose') { computerScore++; resultText.setText(''); resultText.setStyle({ fill: 0xFFFFFF }); } else { resultText.setText(''); resultText.setStyle({ fill: 0xFFFFFF }); } scoreDisplay.setText(playerScore + '/10 - ' + computerScore + '/10'); // Check for win condition if (playerScore >= 10 || computerScore >= 10) { // Show winner and prevent further play if (playerScore >= 10 && computerScore >= 10) { resultText.setText('Draw'); resultText.setStyle({ fill: 0xFFFFFF }); } else if (playerScore >= 10) { resultText.setText('Player Won'); resultText.setStyle({ fill: 0xFFFFFF }); } else if (computerScore >= 10) { resultText.setText('Computer Won'); resultText.setStyle({ fill: 0xFFFFFF }); } // Do not reset round, keep result visible return; } // Reset for next round after a short delay LK.setTimeout(function () { resetRound(); }, 1200); }, 500); // 0.5s delay to show computer's choice before result } } countdownInterval = LK.setInterval(updateCountdown, 1000); } // --- Show Choices (Visual Feedback) --- function showChoices() { for (var i = 0; i < buttons.length; i++) { var btn = buttons[i]; if (btn.choice === playerChoice) { btn.alpha = 1.0; LK.effects.flashObject(btn, 0x00ff00, 400); } else { btn.alpha = 0.4; } } // Show computer choice as a temporary overlay in the center if (game.computerChoiceSprite) { game.computerChoiceSprite.destroy(); game.computerChoiceSprite = null; } var compSprite; if (computerChoice === 'rock') { compSprite = LK.getAsset('Rock', { width: 400, height: 400, anchorX: 0.5, anchorY: 0.5 }); } else if (computerChoice === 'paper') { compSprite = LK.getAsset('Paper', { width: 400, height: 400, anchorX: 0.5, anchorY: 0.5 }); } else if (computerChoice === 'scissors') { compSprite = LK.getAsset('Scissors', { width: 400, height: 400, anchorX: 0.5, anchorY: 0.5 }); } else { compSprite = LK.getAsset('rps_' + computerChoice, { width: 400, height: 400, anchorX: 0.5, anchorY: 0.5 }); } compSprite.x = 2048 / 2; compSprite.y = 1100; game.addChild(compSprite); game.computerChoiceSprite = compSprite; } // --- Reset for Next Round --- function resetRound() { playerChoice = null; computerChoice = null; resultText.setText(''); for (var i = 0; i < buttons.length; i++) { buttons[i].alpha = 1.0; } if (game.computerChoiceSprite) { game.computerChoiceSprite.destroy(); game.computerChoiceSprite = null; } } // --- Determine Result --- function getResult(player, computer) { if (player === computer) return 'draw'; if (player === 'rock' && computer === 'scissors' || player === 'paper' && computer === 'rock' || player === 'scissors' && computer === 'paper') { return 'win'; } return 'lose'; }
===================================================================
--- original.js
+++ change.js
@@ -15,22 +15,14 @@
var resultText = null;
var playerScore = 0;
var computerScore = 0;
// --- Create GUI Score Display ---
-var playerScoreDisplay = new Text2('Player 0/10', {
+var scoreDisplay = new Text2('0/10 - 0/10', {
size: 100,
fill: 0xFFFFFF
});
-playerScoreDisplay.anchor.set(0, 0);
-playerScoreDisplay.x = 40;
-LK.gui.top.addChild(playerScoreDisplay);
-var computerScoreDisplay = new Text2('Computer 0/10', {
- size: 100,
- fill: 0xFFFFFF
-});
-computerScoreDisplay.anchor.set(1, 0);
-computerScoreDisplay.x = LK.gui.top.width - 40;
-LK.gui.top.addChild(computerScoreDisplay);
+scoreDisplay.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreDisplay);
// --- Create Result Text ---
resultText = new Text2('', {
size: 120,
fill: 0xFFFFFF
@@ -152,26 +144,25 @@
LK.setTimeout(function () {
var result = getResult(playerChoice, computerChoice);
if (result === 'win') {
playerScore++;
- resultText.setText('Player Won');
+ resultText.setText('');
resultText.setStyle({
fill: 0xFFFFFF
});
} else if (result === 'lose') {
computerScore++;
- resultText.setText('Computer Won');
+ resultText.setText('');
resultText.setStyle({
fill: 0xFFFFFF
});
} else {
- resultText.setText('draw');
+ resultText.setText('');
resultText.setStyle({
fill: 0xFFFFFF
});
}
- playerScoreDisplay.setText('Player ' + playerScore + '/10');
- computerScoreDisplay.setText('Computer ' + computerScore + '/10');
+ scoreDisplay.setText(playerScore + '/10 - ' + computerScore + '/10');
// Check for win condition
if (playerScore >= 10 || computerScore >= 10) {
// Show winner and prevent further play
if (playerScore >= 10 && computerScore >= 10) {
@@ -179,14 +170,14 @@
resultText.setStyle({
fill: 0xFFFFFF
});
} else if (playerScore >= 10) {
- resultText.setText('Player Won the Game!');
+ resultText.setText('Player Won');
resultText.setStyle({
fill: 0xFFFFFF
});
} else if (computerScore >= 10) {
- resultText.setText('Computer Won the Game!');
+ resultText.setText('Computer Won');
resultText.setStyle({
fill: 0xFFFFFF
});
}