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); self.playerScore = 0; self.enemyScore = 0; 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 playerScoreTxt = new Text2('Player Score: 0', { size: 100, fill: "#ffffff" }); playerScoreTxt.anchor.set(0, 1); LK.gui.bottomLeft.addChild(playerScoreTxt); var enemyScoreTxt = new Text2('Enemy Score: 0', { size: 100, fill: "#ffffff" }); enemyScoreTxt.anchor.set(1, 1); LK.gui.bottomRight.addChild(enemyScoreTxt); 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!'; self.playerScore++; } else { result = 'You lose!'; self.enemyScore++; } resultTxt.setText(result); playerScoreTxt.setText('Player Score: ' + self.playerScore); enemyScoreTxt.setText('Enemy Score: ' + self.enemyScore); }); }); });
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,6 @@
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'];
@@ -9,25 +8,38 @@
};
});
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);
+ self.playerScore = 0;
+ self.enemyScore = 0;
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 playerScoreTxt = new Text2('Player Score: 0', {
+ size: 100,
+ fill: "#ffffff"
+ });
+ playerScoreTxt.anchor.set(0, 1);
+ LK.gui.bottomLeft.addChild(playerScoreTxt);
+ var enemyScoreTxt = new Text2('Enemy Score: 0', {
+ size: 100,
+ fill: "#ffffff"
+ });
+ enemyScoreTxt.anchor.set(1, 1);
+ LK.gui.bottomRight.addChild(enemyScoreTxt);
enemy.x = 2048 / 2 - 200;
enemy.y = 2732 / 2;
player.x = 2048 / 2 + 200;
player.y = 2732 / 2;
@@ -44,16 +56,15 @@
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!';
+ self.playerScore++;
} else {
result = 'You lose!';
+ self.enemyScore++;
}
- if (result === 'You win!') {
- player.winCount++;
- } else if (result === 'You lose!') {
- enemy.winCount++;
- }
- resultTxt.setText(result + ' Player Wins: ' + player.winCount + ' Enemy Wins: ' + enemy.winCount);
+ resultTxt.setText(result);
+ playerScoreTxt.setText('Player Score: ' + self.playerScore);
+ enemyScoreTxt.setText('Enemy Score: ' + self.enemyScore);
});
});
});