User prompt
show the explosion animation also when computer lose
Code edit (7 edits merged)
Please save this source code
User prompt
factorize the 3 blocks if (candyCanes.length === 0) {...} in a global function with all required parameters
User prompt
Fix Bug: 'ReferenceError: handleEndGame is not defined' in this line: 'handleEndGame(self, playerTurn);' Line Number: 266
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in this line: 'if (context.candyCanes.length === 0) {' Line Number: 171
User prompt
fix game end because the annimations doesn't show anymore !
Code edit (9 edits merged)
Please save this source code
User prompt
Add a popup at the begining to let the user choose between 1 or 2 players mode
User prompt
gameState should change to 1 only after mode selection
User prompt
bug : onePlayerButton & twoPlayerButton are not visible
User prompt
place the mode buttons at the vertical center
Code edit (16 edits merged)
Please save this source code
User prompt
create the candies only after mode is selected
User prompt
add a gui text in front of each button 1 and 2
Code edit (7 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
make the one and two PlayerText bold
Code edit (18 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
When In 2 players mode computer is controlled by mouse y like for the player
User prompt
fix event up and down only work for 1 player
User prompt
fix turn is not changing
User prompt
fix computer doesn't play in 1 player mode
Code edit (1 edits merged)
Please save this source code
User prompt
current code of up and down events is for 1 player mode, add the tests playerMode === 1
===================================================================
--- original.js
+++ change.js
@@ -3,9 +3,9 @@
var isAnimatingEnd = false;
var playerTurn = true;
var playerSelecting = false;
var computerArmOffset = 120;
-var debug = false;
+var debug = true;
function addShadow(name, x, y) {
var shadow = new Container();
shadow.createAsset(name, name, 0, 0);
shadow.width = name === 'candyCaneShadow' ? shadow.width / 4 : shadow.width;
@@ -104,28 +104,8 @@
candyToRemove.destroy();
}
}
}
-function startGame(self, candyCanes, playerMode) {
- console.log("startGame... playerMode = " + playerMode, Game.candyCanes);
- return;
- fade(self.player, 500, true);
- gameState = 1;
- self.playerMode = playerMode;
- candiesNumber = Math.floor(Math.random() * 3) + 10;
- for (var i = 0; i < candiesNumber; 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 + candiesNumber * 190 + 20;
- candyCanes.push(lastCandyCane);
- self.addChild(lastCandyCane);
-}
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.createAsset('explosion', 'Explosion Graphics', .5, .5);
self.x = 2048 / 2 + 30;
@@ -206,9 +186,9 @@
self.createAsset('computerPlayer', 'Computer Player', .5, .5);
self.alpha = 0;
self.update = function () {};
});
-var PlayerModePopup = Container.expand(function () {
+var PlayerModePopup = Container.expand(function (game) {
var self = Container.call(this);
self.createAsset('playerModePopup', 'Player Mode Popup', 0.5, 0.5);
self.x = 2048 / 2;
self.y = 2732 / 2;
@@ -226,19 +206,17 @@
onePlayerButton.y = 140;
onePlayerButton.alpha = 1;
onePlayerButton.on('down', function () {
self.destroy();
- gameState = 1;
- startGame(1);
+ game.initGame(1);
});
var twoPlayerButton = self.createAsset('twoPlayerButton', 'Two Player Button', 0.5, 0.5);
twoPlayerButton.x = 300;
twoPlayerButton.y = 140;
twoPlayerButton.alpha = 1;
twoPlayerButton.on('down', function () {
self.destroy();
- gameState = 1;
- startGame(2);
+ game.initGame(2);
});
self.addChild(onePlayerButton);
self.addChild(twoPlayerButton);
;
@@ -307,8 +285,28 @@
self.computerPlayer = self.addChild(new ComputerPlayer());
self.computerPlayer.x = 1648;
self.computerPlayer.y = 1324;
setSelectionPositions(self, candyCanes.length > 0 ? candyCanes[0].y : 0);
+ self.initGame = function (playerMode) {
+ console.log("initGame... playerMode = " + playerMode);
+ self.playerMode = playerMode;
+ candiesNumber = Math.floor(Math.random() * 3) + 10;
+ for (var i = 0; i < candiesNumber; 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 + candiesNumber * 190 + 20;
+ candyCanes.push(lastCandyCane);
+ self.addChild(lastCandyCane);
+ setSelectionPositions(self, candyCanes.length > 0 ? candyCanes[0].y : 0);
+ fade(self.player, 500, true);
+ gameState = 1;
+ };
stage.on('down', function (obj) {
if (gameState === 2 && !isAnimatingEnd) {
LK.showGameOver();
return;
@@ -393,7 +391,7 @@
}
self.computerCandiesText.setText(self.computerCandiesCount ? self.computerCandiesCount.toString() : "?");
}
});
- var playerModePopup = new PlayerModePopup();
+ var playerModePopup = new PlayerModePopup(self);
self.addChild(playerModePopup);
});
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