User prompt
Fix Bug: 'TypeError: candyCanes[0] is undefined' in this line: 'var minY = candyCanes[0].y + 120;' Line Number: 31
Code edit (2 edits merged)
Please save this source code
User prompt
automate computer turn by animating his candy selection
Code edit (1 edits merged)
Please save this source code
User prompt
fix the players turns
User prompt
bug : player plays twice
User prompt
bug Player not fading out when it's computer turn
User prompt
call setSelectionPositions before fading in
User prompt
add a small delay before and after computer plays
Code edit (1 edits merged)
Please save this source code
User prompt
wait for the computer fade out to complete before calling setSelectionPositions
Code edit (2 edits merged)
Please save this source code
User prompt
bug : candies doesn't go bigger when computer selects them
User prompt
Fix candies enlargement on computer selecttion. Candies should go bigger dynamically durring computer movement like they do for the player
User prompt
player selection should start only when mouse is down
User prompt
Fix Bug: 'ReferenceError: candyCanes is not defined' in this line: 'handleSelection(event, self, candyCanes);' Line Number: 84
User prompt
Fix Bug: 'TypeError: candyCanes is undefined' in this line: 'if (candyCanes.length === 0) {' Line Number: 32
User prompt
Fix Bug: 'Timeout.tick error: candyCanes[(candiesToPick - 1)] is undefined' in this line: 'var targetY = candyCanes[candiesToPick - 1].y;' Line Number: 92
User prompt
Fix Bug: 'Timeout.tick error: candyCanes[(candiesToPick - 1)] is undefined' in this line: 'var targetY = candyCanes.length >= candiesToPick ? candyCanes[candiesToPick - 1].y : 0;' Line Number: 92
User prompt
set the PlayerTrun to random
User prompt
fix at start, even if playerturn is false, i'ts the player who plays !
User prompt
extract the logic of candies removal in a global function with the needed arguments. use it for player and computer selection
User prompt
Fix Bug: 'Timeout.tick error: removeCandies is not defined' in this line: 'removeCandies(candyCanes, candiesToPick);' Line Number: 100
User prompt
Fix Bug: 'ReferenceError: removeCandies is not defined' in this line: 'removeCandies(candyCanes, self.selectedCandiesCount);' Line Number: 191
Code edit (4 edits merged)
Please save this source code
function addShadow(name, x, y) {
var shadow = new Container();
shadow.createAsset(name, name, 0, 0);
shadow.width = name === 'candyCaneShadow' ? shadow.width / 4 : shadow.width;
shadow.x = x;
shadow.y = y;
shadow.alpha = 0.8;
return shadow;
}
function addShadows(self, x1, x2, x3, y) {
self.addChildAt(addShadow('candyCaneShadow', x1, y), 0);
self.addChildAt(addShadow('candyCaneShadow', x2, y), 0);
self.addChildAt(addShadow('candyCaneShadowCentral', x3, y), 0);
}
function fade(target, duration, fadeIn) {
var alphaTarget = fadeIn ? 1 : 0;
var alphaDelta = (alphaTarget - target.alpha) / (duration / (1000 / 60));
var fadeInterval = LK.setInterval(function () {
if (fadeIn && target.alpha < 1 || !fadeIn && target.alpha > 0) {
target.alpha += alphaDelta;
if (fadeIn && target.alpha >= 1 || !fadeIn && target.alpha <= 0) {
target.alpha = alphaTarget;
LK.clearInterval(fadeInterval);
}
}
}, 1000 / 60);
}
function handleSelection(obj, player, candyCanes) {
var event = obj.event;
var pos = event.getLocalPosition(player.parent);
var minY = candyCanes.length > 0 ? candyCanes[0].y + 120 : 0;
var maxY = candyCanes.length > 2 ? candyCanes[2].y + 140 : candyCanes[candyCanes.length - 1].y + 140;
player.y = Math.max(minY, Math.min(maxY, pos.y));
if (player.y < candyCanes[0].y + 240) {
player.parent.selectedCandiesCount = 1;
} else if (player.y < candyCanes[1].y + 240) {
player.parent.selectedCandiesCount = 2;
} else if (player.y < candyCanes[2].y + 240) {
player.parent.selectedCandiesCount = 3;
}
for (var i = 0; i < candyCanes.length; i++) {
if (i < player.parent.selectedCandiesCount) {
candyCanes[i].scale.set(1.1);
} else {
candyCanes[i].scale.set(1);
}
}
}
function computeComputerCandiesCount(nbSticksLeft) {
var count = 0;
var candiesLeft = nbSticksLeft;
var targetModulo = (candiesLeft - 1) % 4;
count = targetModulo === 0 ? 1 : targetModulo;
return count;
}
;
function setSelectionPositions(self, refY) {
self.player.y = refY + 120;
self.computerPlayer.y = refY + 60;
}
var LastCandyCane = Container.expand(function () {
var self = Container.call(this);
var candyCaneGraphics = self.createAsset('lastCandyCane', 'Last Candy Cane', .5, .5);
addShadows(self, -350, 75, -255, -25);
});
var CandyCane = Container.expand(function () {
var self = Container.call(this);
var candyCaneGraphics = self.createAsset('candyCane', 'Candy Cane', .5, .5);
addShadows(self, -320, 120, -225, -10);
self.pick = function () {
self.parent.selectedCandiesCount++;
console.log("Picked ", self);
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
self.createAsset('player', 'Player', .5, .5);
self.alpha = 0;
self.pickCandyCane = function () {
self.computerPlayer.pickCandyCane();
self.alpha = 0;
};
});
var ComputerPlayer = Container.expand(function () {
var self = Container.call(this);
self.createAsset('computerPlayer', 'Computer Player', .5, .5);
self.alpha = 0;
self.pickCandyCane = function () {
playerTurn = !playerTurn;
if (playerTurn) {} else {
self.alpha = 1;
self.parent.addChild(self);
}
self.alpha = 1;
};
self.update = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var playerTurn = true;
var candyCanes = [];
self.selectedCandiesCount = 0;
self.computerCandiesCount = 0;
var background = self.createAsset('background', 'Game Background', 0.2545, 0.215);
self.addChildAt(background, 0);
self.selectedCandiesText = new Text2("0", {
size: 100,
fill: "#00FF00"
});
self.selectedCandiesText.anchor.set(0, 0);
LK.gui.topLeft.addChild(self.selectedCandiesText);
self.computerCandiesText = new Text2("?", {
size: 100,
fill: "#FF0000"
});
self.computerCandiesText.anchor.set(1, 0);
LK.gui.topRight.addChild(self.computerCandiesText);
self.playerYPositionText = new Text2('', {
size: 100,
fill: "#00FF00"
});
self.playerYPositionText.anchor.set(-0, 1);
LK.gui.bottomLeft.addChild(self.playerYPositionText);
self.computerYPositionText = new Text2('', {
size: 100,
fill: "#00FF00"
});
self.computerYPositionText.anchor.set(1, 1);
LK.gui.bottomRight.addChild(self.computerYPositionText);
self.candyCaneYPositionText = new Text2('', {
size: 100,
fill: "#00FF00"
});
self.candyCaneYPositionText.anchor.set(0.5, 0);
LK.gui.topCenter.addChild(self.candyCaneYPositionText);
for (var i = 0; i < 12; i++) {
var candyCane = new CandyCane();
candyCane.x = 2048 / 2;
candyCane.y = 270 + i * 190;
candyCanes.push(candyCane);
self.addChild(candyCane);
}
var lastCandyCane = new LastCandyCane();
lastCandyCane.x = 2048 / 2 + 30;
lastCandyCane.y = 250 + 12 * 190 + 20;
candyCanes.push(lastCandyCane);
self.addChild(lastCandyCane);
self.player = self.addChild(new Player());
self.player.x = 400;
self.player.y = 270 + 130;
self.computerPlayer = self.addChild(new ComputerPlayer());
self.computerPlayer.x = 1648;
self.computerPlayer.y = 1324;
setSelectionPositions(self, candyCanes.length > 0 ? candyCanes[0].y : 0);
stage.on('down', function (obj) {
console.log('Mouse down event:', obj);
stage.on('move', function (event) {
handleSelection(event, self.player, candyCanes);
self.selectedCandiesText.setText(self.selectedCandiesCount.toString());
});
});
stage.on('up', function (obj) {
console.log('Mouse up event:', obj);
stage.off('move', handleSelection);
for (var i = 0; i < self.selectedCandiesCount; i++) {
if (candyCanes.length > 0) {
var candyToRemove = candyCanes.shift();
candyToRemove.destroy();
}
}
self.selectedCandiesCount = 0;
self.selectedCandiesText.setText("0");
setSelectionPositions(self, candyCanes.length > 0 ? candyCanes[0].y : 0);
if (playerTurn) {
console.log("Show Computer Player");
fade(self.computerPlayer, 500, true);
fade(self.player, 500, false);
self.computerCandiesCount = computeComputerCandiesCount(candyCanes.length, self.selectedCandiesCount);
} else {
console.log("Show Human Player");
fade(self.computerPlayer, 500, false);
fade(self.player, 500, true);
self.computerCandiesCount = 0;
}
playerTurn = !playerTurn;
});
LK.on('tick', function () {
if (self.player && self.playerYPositionText) {
self.playerYPositionText.setText('Py: ' + Math.round(self.player.y));
}
if (self.computerPlayer && self.computerYPositionText) {
self.computerYPositionText.setText('Ky: ' + Math.round(self.computerPlayer.y));
}
if (candyCanes.length > 0 && self.candyCaneYPositionText) {
self.candyCaneYPositionText.setText('Cy: ' + Math.round(candyCanes[0].y));
}
self.computerCandiesText.setText(self.computerCandiesCount ? self.computerCandiesCount.toString() : "?");
});
LK.setTimeout(function () {
fade(self.player, 500, true);
}, 1000);
});
a christmas wooden board Background image. High contrast. No shadows.
a vertical christmas wooden board with snow, and decorations on its sides Background image. High contrast. No shadows.
a photo-realistic white and red vertical candy stick slice Single Game Texture. No background. High contrast. No shadows.
a horizontal santa's arm with a white glove and the index pointing to the right Single Game Texture. No background. High contrast. No shadows.
an green hairy grinch's arm, pointing in the horizontal direction, the index finger pointing to the left Single Game Texture. No background. High contrast. No shadows.
a photo-realistic white and red twisted candy stick slice in vertical position and with an extinguished wick. At its center, a simple white rectangular "TNT" sticker in the same direction as the stick Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a top view of a TNT explosion fire Background image. High contrast. No shadows.
A funny Santa Claus disheveled and covered by black soot after an explosion. stary night. High contrast.
a futuristic white robot arm. horizontal direction. the index finger pointing to the left. Single Game Texture. No background. High contrast. No shadows.
A old super hero Santa Claus holding a candy cane in his hand High contrast.
frame of an empty christmas themed popup with a decorated border User interface
a single mat rounded empty button User interface