User prompt
Highlight the choice in the color of the players, who choose it. Red for enemy, green for the player.
User prompt
I want to see the wins of each player at the bottom of board.
User prompt
Give both players a win counter under their id objects.
User prompt
Give both players a win counter.
User prompt
Give the information to the player, what the enemy choose and what the player choose. Also a text, why the player won or loos. Add also an info button at the top right corner. It opens a window with the rules, which object wins against which object.
Initial prompt
Scissors Stone Paper
var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5); self.choice = null; self.choose = function () { var choices = ['scissors', 'stone', 'paper']; self.choice = choices[Math.floor(Math.random() * choices.length)]; }; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', .5, .5); self.choice = null; self.choose = function (choice) { self.choice = choice; }; }); var Game = Container.expand(function () { var self = Container.call(this); var enemy = self.addChild(new Enemy()); var player = self.addChild(new Player()); var resultTxt = new Text2('', { size: 150, fill: "#ffffff" }); resultTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(resultTxt); var infoBtn = LK.getAsset('info', 'Info button', 0.5, 0.5); infoBtn.x = 2048 - 100; infoBtn.y = 100; LK.gui.topRight.addChild(infoBtn); var rulesWindow = new Container(); rulesWindow.visible = false; var rulesBackground = rulesWindow.createAsset('rulesBg', 'Rules background', 0.5, 0.5); var rulesText = new Text2('Scissors cut paper, paper covers stone, stone blunts scissors.', { size: 100, fill: "#ffffff" }); rulesText.anchor.set(0.5, 0.5); rulesText.x = 2048 / 2; rulesText.y = 2732 / 2; rulesWindow.addChild(rulesText); LK.gui.addChild(rulesWindow); infoBtn.on('down', function () { rulesWindow.visible = !rulesWindow.visible; }); enemy.x = 2048 / 2 - 200; enemy.y = 2732 / 2; player.x = 2048 / 2 + 200; player.y = 2732 / 2; var choices = ['scissors', 'stone', 'paper']; choices.forEach(function (choice, index) { var choiceBtn = LK.getAsset(choice, 'Choice button', .5, .5); choiceBtn.x = 2048 / 3 * index + 2048 / 6; choiceBtn.y = 2732 - 200; self.addChild(choiceBtn); choiceBtn.on('down', function () { player.choose(choice); enemy.choose(); var result = ''; if (player.choice === enemy.choice) { result = 'Draw!'; } else if (player.choice === 'scissors' && enemy.choice === 'paper' || player.choice === 'stone' && enemy.choice === 'scissors' || player.choice === 'paper' && enemy.choice === 'stone') { result = 'You win!'; } else { result = 'You lose!'; } var reason = ''; if (player.choice === enemy.choice) { reason = 'Both chose ' + player.choice + '.'; } else if (player.choice === 'scissors' && enemy.choice === 'paper') { reason = 'Scissors cut paper.'; } else if (player.choice === 'stone' && enemy.choice === 'scissors') { reason = 'Stone blunts scissors.'; } else if (player.choice === 'paper' && enemy.choice === 'stone') { reason = 'Paper covers stone.'; } else if (enemy.choice === 'scissors' && player.choice === 'paper') { reason = 'Scissors cut paper.'; } else if (enemy.choice === 'stone' && player.choice === 'scissors') { reason = 'Stone blunts scissors.'; } else if (enemy.choice === 'paper' && player.choice === 'stone') { reason = 'Paper covers stone.'; } resultTxt.setText('Player chose ' + player.choice + '. Enemy chose ' + enemy.choice + '. ' + result + ' ' + reason); }); }); });
===================================================================
--- original.js
+++ change.js
@@ -24,8 +24,27 @@
fill: "#ffffff"
});
resultTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(resultTxt);
+ var infoBtn = LK.getAsset('info', 'Info button', 0.5, 0.5);
+ infoBtn.x = 2048 - 100;
+ infoBtn.y = 100;
+ LK.gui.topRight.addChild(infoBtn);
+ var rulesWindow = new Container();
+ rulesWindow.visible = false;
+ var rulesBackground = rulesWindow.createAsset('rulesBg', 'Rules background', 0.5, 0.5);
+ var rulesText = new Text2('Scissors cut paper, paper covers stone, stone blunts scissors.', {
+ size: 100,
+ fill: "#ffffff"
+ });
+ rulesText.anchor.set(0.5, 0.5);
+ rulesText.x = 2048 / 2;
+ rulesText.y = 2732 / 2;
+ rulesWindow.addChild(rulesText);
+ LK.gui.addChild(rulesWindow);
+ infoBtn.on('down', function () {
+ rulesWindow.visible = !rulesWindow.visible;
+ });
enemy.x = 2048 / 2 - 200;
enemy.y = 2732 / 2;
player.x = 2048 / 2 + 200;
player.y = 2732 / 2;
@@ -45,8 +64,24 @@
result = 'You win!';
} else {
result = 'You lose!';
}
- resultTxt.setText(result);
+ var reason = '';
+ if (player.choice === enemy.choice) {
+ reason = 'Both chose ' + player.choice + '.';
+ } else if (player.choice === 'scissors' && enemy.choice === 'paper') {
+ reason = 'Scissors cut paper.';
+ } else if (player.choice === 'stone' && enemy.choice === 'scissors') {
+ reason = 'Stone blunts scissors.';
+ } else if (player.choice === 'paper' && enemy.choice === 'stone') {
+ reason = 'Paper covers stone.';
+ } else if (enemy.choice === 'scissors' && player.choice === 'paper') {
+ reason = 'Scissors cut paper.';
+ } else if (enemy.choice === 'stone' && player.choice === 'scissors') {
+ reason = 'Stone blunts scissors.';
+ } else if (enemy.choice === 'paper' && player.choice === 'stone') {
+ reason = 'Paper covers stone.';
+ }
+ resultTxt.setText('Player chose ' + player.choice + '. Enemy chose ' + enemy.choice + '. ' + result + ' ' + reason);
});
});
});