User prompt
The choices should be on bigger clickable buttons
User prompt
Now replace the background with an image
User prompt
Add a blue background
User prompt
Give Contrairian, One Step Ahead and Copycat a random first choice before they use their usual behavior
User prompt
The end text is not readable. Not more then 2 words in a line
User prompt
Can you put line 184 in the code enemy.choose(); move up 2 lines
User prompt
Can you put line 185 in the code enemy.choose(); move up 2 lines
User prompt
Make comments to the code
User prompt
Same for the copycat. He should choose my last choice, not the current choice
User prompt
Fix that
User prompt
If the player did a total win against an enemy type, remove this enemy type from the list of possible enemies.
User prompt
Move the total win counter above the player win counter
User prompt
Put the total win counter on the top of the other counters
User prompt
Add a total win counter. If the player click on it, a closable popup is revealed with the names of enemies, you already beated
User prompt
Fix Bug: 'TypeError: self.resetGame is not a function. (In 'self.resetGame()', 'self.resetGame' is undefined)' in this line: 'self.resetGame();' Line Number: 140
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.enemyTypesDefeated.push')' in this line: 'self.enemyTypesDefeated.push(enemy.type);' Line Number: 134
var PlayerChoiceGraphic = Container.expand(function (choice) {
var self = Container.call(this);
var graphic = self.createAsset(choice, 'Player choice graphic', 0.5, 0.5);
self.getChoice = function () {
return graphic;
};
});
var EnemyChoiceGraphic = Container.expand(function (choice) {
var self = Container.call(this);
var graphic = self.createAsset(choice, 'Enemy choice graphic', 0.5, 0.5);
self.getChoice = function () {
return graphic;
};
});
var Enemy = Container.expand(function (type, game) {
var self = Container.call(this);
self.choice = null;
self.type = type;
self.game = game;
self.choose = function () {
var choices;
switch (self.type) {
case 1:
self.name = 'Stone Lover';
choices = ['stone', 'stone', 'scissors', 'paper'];
break;
case 2:
self.name = 'Scissors Fan';
choices = ['scissors', 'scissors', 'stone', 'paper'];
break;
case 3:
self.name = 'Paper Enthusiast';
choices = ['paper', 'paper', 'scissors', 'stone'];
break;
case 4:
self.name = 'Stonephobic';
choices = ['scissors', 'stone', 'stone', 'paper', 'paper'];
break;
case 5:
self.name = 'Scissorshater';
choices = ['stone', 'scissors', 'scissors', 'paper', 'paper'];
break;
case 6:
self.name = 'PaperIsUgly';
choices = ['paper', 'scissors', 'scissors', 'stone', 'stone'];
break;
case 7:
self.name = 'Copycat';
choices = [self.game.lastPlayerChoice];
break;
case 8:
self.name = 'One Step Ahead';
choices = [self.game.lastPlayerChoice === 'scissors' ? 'stone' : self.game.lastPlayerChoice === 'stone' ? 'paper' : 'scissors'];
break;
case 9:
self.name = 'Contrarian';
choices = [self.game.lastPlayerChoice === 'scissors' ? 'paper' : self.game.lastPlayerChoice === 'stone' ? 'scissors' : 'stone'];
break;
default:
self.name = 'Balanced';
choices = ['scissors', 'stone', 'paper'];
}
self.choice = choices[Math.floor(Math.random() * choices.length)];
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
self.choice = null;
self.choose = function (choice) {
self.choice = choice;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.enemyTypesDefeated = [];
self.playerScore = 0;
self.enemyScore = 0;
var enemyType = Math.floor(Math.random() * 3) + 1;
var enemy = self.addChild(new Enemy(enemyType, self));
var player = self.addChild(new Player());
self.lastPlayerChoice = null;
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.5, 1);
playerScoreTxt.x = 2048 / 2 - 300;
playerScoreTxt.y = 2732 / 2 - 100;
self.addChild(playerScoreTxt);
self.playerChoiceGraphic = null;
var enemyScoreTxt = new Text2('Enemy Score: 0', {
size: 100,
fill: "#ffffff"
});
enemyScoreTxt.anchor.set(0.5, 1);
enemyScoreTxt.x = 2048 / 2 - 300;
enemyScoreTxt.y = 2732 / 2 + 100;
self.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.scale.set(1.5);
choiceBtn.x = 2048 / 3 * index + 2048 / 6;
choiceBtn.y = 2732 - 200;
self.addChild(choiceBtn);
choiceBtn.on('down', function () {
player.choose(choice);
self.lastPlayerChoice = 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);
if (self.playerScore >= 10) {
resultTxt.setText('You won against ' + enemy.name + '!');
self.enemyTypesDefeated.push(enemy.type);
if (self.enemyTypesDefeated.length === 9) {
resultTxt.setText('Congratulations! You have defeated all enemy types!');
LK.showGameOver();
} else {
self.resetGame();
}
} else if (self.enemyScore >= 10) {
resultTxt.setText('You lost against ' + enemy.name + '. Game Over!');
LK.showGameOver();
}
if (self.playerChoiceGraphic) {
self.playerChoiceGraphic.destroy();
}
self.playerChoiceGraphic = self.addChild(new PlayerChoiceGraphic(player.choice));
self.playerChoiceGraphic.x = 2048 / 2 + 300;
self.playerChoiceGraphic.y = playerScoreTxt.y - 50;
if (self.enemyChoiceGraphic) {
self.enemyChoiceGraphic.destroy();
}
self.enemyChoiceGraphic = self.addChild(new EnemyChoiceGraphic(enemy.choice));
self.enemyChoiceGraphic.x = 2048 / 2 + 300;
self.enemyChoiceGraphic.y = 2732 / 2 + 50;
});
});
});