/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ChoiceButton = Container.expand(function (choiceType) {
var self = Container.call(this);
var buttonShape;
if (choiceType === 'rock') {
buttonShape = self.attachAsset('rockButton', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (choiceType === 'paper') {
buttonShape = self.attachAsset('paperButton', {
anchorX: 0.5,
anchorY: 0.5
});
} else {
buttonShape = self.attachAsset('scissorsButton', {
anchorX: 0.5,
anchorY: 0.5
});
}
var labelText = new Text2(choiceType.toUpperCase(), {
size: 60,
fill: 0xFFFFFF
});
labelText.anchor.set(0.5, 0.5);
self.addChild(labelText);
self.choiceType = choiceType;
self.isEnabled = true;
self.down = function (x, y, obj) {
if (self.isEnabled && gameState === 'waiting') {
LK.getSound('select').play();
tween(buttonShape, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
playerChoice = self.choiceType;
makeAIChoice();
showChoices();
}
};
self.up = function (x, y, obj) {
tween(buttonShape, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
return self;
});
var HandDisplay = Container.expand(function (isPlayer) {
var self = Container.call(this);
var handShape = self.attachAsset(isPlayer ? 'playerHand' : 'aiHand', {
anchorX: 0.5,
anchorY: 0.5
});
self.choiceText = new Text2('?', {
size: 80,
fill: 0xFFFFFF
});
self.choiceText.anchor.set(0.5, 0.5);
self.addChild(self.choiceText);
self.showChoice = function (choice) {
var displayText = choice.charAt(0).toUpperCase() + choice.slice(1);
self.choiceText.setText(displayText);
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
});
};
self.reset = function () {
self.choiceText.setText('?');
self.scaleX = 1.0;
self.scaleY = 1.0;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F4F
});
/****
* Game Code
****/
// Game state variables
var gameState = 'waiting'; // 'waiting', 'showing', 'result'
var playerChoice = null;
var aiChoice = null;
var playerScore = 0;
var aiScore = 0;
var maxRounds = 5;
var currentRound = 1;
// Create background
var bg = game.attachAsset('background', {
x: 0,
y: 0
});
// Create choice buttons
var rockButton = new ChoiceButton('rock');
var paperButton = new ChoiceButton('paper');
var scissorsButton = new ChoiceButton('scissors');
rockButton.x = 2048 / 4;
rockButton.y = 2200;
paperButton.x = 2048 / 2;
paperButton.y = 2200;
scissorsButton.x = 2048 * 3 / 4;
scissorsButton.y = 2200;
game.addChild(rockButton);
game.addChild(paperButton);
game.addChild(scissorsButton);
// Create hand displays
var playerHand = new HandDisplay(true);
var aiHand = new HandDisplay(false);
playerHand.x = 2048 / 3;
playerHand.y = 1400;
aiHand.x = 2048 * 2 / 3;
aiHand.y = 1400;
game.addChild(playerHand);
game.addChild(aiHand);
// Create UI text elements
var titleText = new Text2('Rock Paper Scissors', {
size: 100,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
var roundText = new Text2('Round 1 of 5', {
size: 60,
fill: 0xFFFFFF
});
roundText.anchor.set(0.5, 0);
roundText.y = 150;
LK.gui.top.addChild(roundText);
var scoreText = new Text2('Player: 0 | AI: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(scoreText);
var resultText = new Text2('Choose your move!', {
size: 70,
fill: 0xFFFF00
});
resultText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(resultText);
resultText.y = -200;
// Game functions
function makeAIChoice() {
var choices = ['rock', 'paper', 'scissors'];
var randomIndex = Math.floor(Math.random() * 3);
aiChoice = choices[randomIndex];
}
function showChoices() {
gameState = 'showing';
playerHand.showChoice(playerChoice);
aiHand.showChoice(aiChoice);
LK.setTimeout(function () {
determineWinner();
}, 1000);
}
function determineWinner() {
gameState = 'result';
var result = '';
if (playerChoice === aiChoice) {
result = 'It\'s a tie!';
LK.getSound('tie').play();
LK.effects.flashScreen(0xFFFF00, 500);
} else if (playerChoice === 'rock' && aiChoice === 'scissors' || playerChoice === 'paper' && aiChoice === 'rock' || playerChoice === 'scissors' && aiChoice === 'paper') {
result = 'You win this round!';
playerScore++;
LK.getSound('win').play();
LK.effects.flashScreen(0x00FF00, 500);
} else {
result = 'AI wins this round!';
aiScore++;
LK.getSound('lose').play();
LK.effects.flashScreen(0xFF0000, 500);
}
resultText.setText(result);
updateScore();
currentRound++;
if (currentRound > maxRounds) {
LK.setTimeout(function () {
endGame();
}, 2000);
} else {
LK.setTimeout(function () {
nextRound();
}, 2000);
}
}
function updateScore() {
scoreText.setText('Player: ' + playerScore + ' | AI: ' + aiScore);
roundText.setText('Round ' + currentRound + ' of ' + maxRounds);
}
function nextRound() {
gameState = 'waiting';
playerChoice = null;
aiChoice = null;
playerHand.reset();
aiHand.reset();
resultText.setText('Choose your move!');
updateScore();
}
function endGame() {
if (playerScore > aiScore) {
resultText.setText('YOU WIN THE GAME!');
LK.setScore(playerScore);
LK.showYouWin();
} else if (aiScore > playerScore) {
resultText.setText('AI WINS THE GAME!');
LK.showGameOver();
} else {
resultText.setText('GAME TIED!');
LK.showGameOver();
}
}
game.update = function () {
// Main game loop - no continuous updates needed for this turn-based game
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,244 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var ChoiceButton = Container.expand(function (choiceType) {
+ var self = Container.call(this);
+ var buttonShape;
+ if (choiceType === 'rock') {
+ buttonShape = self.attachAsset('rockButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else if (choiceType === 'paper') {
+ buttonShape = self.attachAsset('paperButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else {
+ buttonShape = self.attachAsset('scissorsButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ var labelText = new Text2(choiceType.toUpperCase(), {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ labelText.anchor.set(0.5, 0.5);
+ self.addChild(labelText);
+ self.choiceType = choiceType;
+ self.isEnabled = true;
+ self.down = function (x, y, obj) {
+ if (self.isEnabled && gameState === 'waiting') {
+ LK.getSound('select').play();
+ tween(buttonShape, {
+ scaleX: 0.9,
+ scaleY: 0.9
+ }, {
+ duration: 100
+ });
+ playerChoice = self.choiceType;
+ makeAIChoice();
+ showChoices();
+ }
+ };
+ self.up = function (x, y, obj) {
+ tween(buttonShape, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 100
+ });
+ };
+ return self;
+});
+var HandDisplay = Container.expand(function (isPlayer) {
+ var self = Container.call(this);
+ var handShape = self.attachAsset(isPlayer ? 'playerHand' : 'aiHand', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.choiceText = new Text2('?', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ self.choiceText.anchor.set(0.5, 0.5);
+ self.addChild(self.choiceText);
+ self.showChoice = function (choice) {
+ var displayText = choice.charAt(0).toUpperCase() + choice.slice(1);
+ self.choiceText.setText(displayText);
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 300,
+ easing: tween.bounceOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200
+ });
+ }
+ });
+ };
+ self.reset = function () {
+ self.choiceText.setText('?');
+ self.scaleX = 1.0;
+ self.scaleY = 1.0;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2F4F4F
+});
+
+/****
+* Game Code
+****/
+// Game state variables
+var gameState = 'waiting'; // 'waiting', 'showing', 'result'
+var playerChoice = null;
+var aiChoice = null;
+var playerScore = 0;
+var aiScore = 0;
+var maxRounds = 5;
+var currentRound = 1;
+// Create background
+var bg = game.attachAsset('background', {
+ x: 0,
+ y: 0
+});
+// Create choice buttons
+var rockButton = new ChoiceButton('rock');
+var paperButton = new ChoiceButton('paper');
+var scissorsButton = new ChoiceButton('scissors');
+rockButton.x = 2048 / 4;
+rockButton.y = 2200;
+paperButton.x = 2048 / 2;
+paperButton.y = 2200;
+scissorsButton.x = 2048 * 3 / 4;
+scissorsButton.y = 2200;
+game.addChild(rockButton);
+game.addChild(paperButton);
+game.addChild(scissorsButton);
+// Create hand displays
+var playerHand = new HandDisplay(true);
+var aiHand = new HandDisplay(false);
+playerHand.x = 2048 / 3;
+playerHand.y = 1400;
+aiHand.x = 2048 * 2 / 3;
+aiHand.y = 1400;
+game.addChild(playerHand);
+game.addChild(aiHand);
+// Create UI text elements
+var titleText = new Text2('Rock Paper Scissors', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+var roundText = new Text2('Round 1 of 5', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+roundText.anchor.set(0.5, 0);
+roundText.y = 150;
+LK.gui.top.addChild(roundText);
+var scoreText = new Text2('Player: 0 | AI: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0.5);
+LK.gui.center.addChild(scoreText);
+var resultText = new Text2('Choose your move!', {
+ size: 70,
+ fill: 0xFFFF00
+});
+resultText.anchor.set(0.5, 1);
+LK.gui.bottom.addChild(resultText);
+resultText.y = -200;
+// Game functions
+function makeAIChoice() {
+ var choices = ['rock', 'paper', 'scissors'];
+ var randomIndex = Math.floor(Math.random() * 3);
+ aiChoice = choices[randomIndex];
+}
+function showChoices() {
+ gameState = 'showing';
+ playerHand.showChoice(playerChoice);
+ aiHand.showChoice(aiChoice);
+ LK.setTimeout(function () {
+ determineWinner();
+ }, 1000);
+}
+function determineWinner() {
+ gameState = 'result';
+ var result = '';
+ if (playerChoice === aiChoice) {
+ result = 'It\'s a tie!';
+ LK.getSound('tie').play();
+ LK.effects.flashScreen(0xFFFF00, 500);
+ } else if (playerChoice === 'rock' && aiChoice === 'scissors' || playerChoice === 'paper' && aiChoice === 'rock' || playerChoice === 'scissors' && aiChoice === 'paper') {
+ result = 'You win this round!';
+ playerScore++;
+ LK.getSound('win').play();
+ LK.effects.flashScreen(0x00FF00, 500);
+ } else {
+ result = 'AI wins this round!';
+ aiScore++;
+ LK.getSound('lose').play();
+ LK.effects.flashScreen(0xFF0000, 500);
+ }
+ resultText.setText(result);
+ updateScore();
+ currentRound++;
+ if (currentRound > maxRounds) {
+ LK.setTimeout(function () {
+ endGame();
+ }, 2000);
+ } else {
+ LK.setTimeout(function () {
+ nextRound();
+ }, 2000);
+ }
+}
+function updateScore() {
+ scoreText.setText('Player: ' + playerScore + ' | AI: ' + aiScore);
+ roundText.setText('Round ' + currentRound + ' of ' + maxRounds);
+}
+function nextRound() {
+ gameState = 'waiting';
+ playerChoice = null;
+ aiChoice = null;
+ playerHand.reset();
+ aiHand.reset();
+ resultText.setText('Choose your move!');
+ updateScore();
+}
+function endGame() {
+ if (playerScore > aiScore) {
+ resultText.setText('YOU WIN THE GAME!');
+ LK.setScore(playerScore);
+ LK.showYouWin();
+ } else if (aiScore > playerScore) {
+ resultText.setText('AI WINS THE GAME!');
+ LK.showGameOver();
+ } else {
+ resultText.setText('GAME TIED!');
+ LK.showGameOver();
+ }
+}
+game.update = function () {
+ // Main game loop - no continuous updates needed for this turn-based game
+};
\ No newline at end of file