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); self.winCount = 0; 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); self.winCount = 0; 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); 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!'; } if (result === 'You win!') { player.winCount++; } else if (result === 'You lose!') { enemy.winCount++; } resultTxt.setText(result + ' Player Wins: ' + player.winCount + ' Enemy Wins: ' + enemy.winCount); }); }); });
===================================================================
--- original.js
+++ change.js
@@ -1,19 +1,19 @@
var Enemy = Container.expand(function () {
var self = Container.call(this);
+ self.winCount = 0;
var enemyGraphics = self.createAsset('enemy', 'Enemy character', .5, .5);
self.choice = null;
- self.wins = 0;
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);
+ self.winCount = 0;
var playerGraphics = self.createAsset('player', 'Player character', .5, .5);
self.choice = null;
- self.wins = 0;
self.choose = function (choice) {
self.choice = choice;
};
});
@@ -48,12 +48,12 @@
} else {
result = 'You lose!';
}
if (result === 'You win!') {
- player.wins++;
+ player.winCount++;
} else if (result === 'You lose!') {
- enemy.wins++;
+ enemy.winCount++;
}
- resultTxt.setText(result + ' Player: ' + player.wins + ' wins, Enemy: ' + enemy.wins + ' wins');
+ resultTxt.setText(result + ' Player Wins: ' + player.winCount + ' Enemy Wins: ' + enemy.winCount);
});
});
});