User prompt
implement checkSquares checking all BoardBox in boxes. for each BoardBox, update isSet value to true, if top, right, bottom and left lines have their isSet true. console log the number of set Boxes.
Code edit (22 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: gameInstance.player1Icon.alpha.set is not a function' in this line: 'gameInstance.player1Icon.alpha.set(playingPlayer === 1 ? 1 : 0.6);' Line Number: 69
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
BoardBox will simplify the game struture. Fill a global array 'boxes' of BoardBox in the creation loop. Just add th new array, don't change current loop logic
User prompt
BoardBox will simplify the game struture. Fill a global array 'boxes' of BoardBox in the creation loop
Code edit (1 edits merged)
Please save this source code
User prompt
fix lines instanciation to have row and col from 0 to 12 only
Code edit (1 edits merged)
Please save this source code
User prompt
Fix BoardLine instantiations to ensure that cols and rows of BoardLines are unique numbers from 0 to 12
User prompt
Fix BoardLine instantiations to ensure that cols and rows of BoardLines are unique numbers
User prompt
Fix BoardLine create to ensure cols and rows of BoardLines are unique
Code edit (1 edits merged)
Please save this source code
User prompt
in activateLine, find the BoardLine in gameInstance.lines corresponding to the current line col and row and update its isSet value
User prompt
in activateLine, update the corresponding line isSet value
Code edit (1 edits merged)
Please save this source code
User prompt
update BoardLine to be a basic js class not an Container.expand
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
fix BoardLine creation to provide correct row and col arguments
User prompt
Fix Bug: 'Uncaught ReferenceError: Boardline is not defined' in this line: 'var bLine = new Boardline(0, 0, false);' Line Number: 129
Code edit (3 edits merged)
Please save this source code
User prompt
in Game function, for lines array, in addition of HorizontalLine and VerticalLine objects create a dedicated class with only col, row and isSet to add in the lines array
User prompt
in Game function, for lines array, don't add HorizontalLine and VerticalLine objects but create a dedicated class with only col, row and isSet
var Line = Container.expand(function (row, col, isHorizontal, gameInstance) { var self = Container.call(this); var lineGraphics = self.createAsset(isHorizontal ? 'lineHorizontal' : 'lineVertical', 'Line Graphics', isHorizontal ? 0 : 0.5, isHorizontal ? 0.5 : 0); lineGraphics.alpha = 0.3; self.playerNumber = null; self.col = col; self.row = row; self.isSet = false; self.setLength = function (length) { if (isHorizontal) { lineGraphics.width = length; } else { lineGraphics.height = length; } }; self.on('down', function () { if (!self.isSet) { activateLine(self, currentPlayer, lineGraphics, gameInstance); console.log("Setting " + row + "," + col); console.log("boxes :", gameInstance.boxes); self.isSet = true; } }); return self; }); var Dot = Container.expand(function () { var self = Container.call(this); var dotGraphics = self.createAsset('dot', 'Dot Graphics', .5, .5); self.connect = function () {}; }); var Square = Container.expand(function () { var self = Container.call(this); var squareGraphics = self.createAsset('square', 'Square Graphics', .5, .5); self.isComplete = function () { var topLineComplete = this.topLine && this.topLine.playerNumber !== null; var bottomLineComplete = this.bottomLine && this.bottomLine.playerNumber !== null; var leftLineComplete = this.leftLine && this.leftLine.playerNumber !== null; var rightLineComplete = this.rightLine && this.rightLine.playerNumber !== null; return topLineComplete && bottomLineComplete && leftLineComplete && rightLineComplete; }; }); var PlayerIcon = Container.expand(function (playerNumber) { var self = Container.call(this); var iconAsset = playerNumber === 1 ? 'player1Icon' : 'player2Icon'; var playerIconGraphics = self.createAsset(iconAsset, 'Player ' + playerNumber + ' Icon', 0.5, 0.5); playerIconGraphics.tint = playerNumber === 2 ? 0x00FF00 : playerIconGraphics.tint; playerIconGraphics.tint = playerNumber === 1 ? 0xFF0000 : playerIconGraphics.tint; return self; }); function BoardLine(row, col) { this.col = col; this.row = row; this.isSet = false; } function BoardBox(row, col, borderLines) { this.col = col; this.row = row; this.top = borderLines[0]; this.right = borderLines[1]; this.bottom = borderLines[2]; this.left = borderLines[3]; this.isFilled = false; this.playerFilled = 0; } function checkSquares(gameInstance) { console.log('Checking squares for completion', gameInstance.lines); } function updatePlayerIcons(gameInstance, playingPlayer) { gameInstance.player1Icon.scale.set(playingPlayer === 1 ? 1.2 : 0.8); gameInstance.player2Icon.scale.set(playingPlayer === 2 ? 1.2 : 0.8); gameInstance.player1Icon.alpha = playingPlayer === 1 ? 1 : 0.6; gameInstance.player2Icon.alpha = playingPlayer === 2 ? 1 : 0.6; } function activateLine(line, playerNumber, lineGraphics, gameInstance) { if (line.playerNumber === null) { line.playerNumber = playerNumber; lineGraphics.alpha = 1; lineGraphics.tint = playerNumber === 1 ? 0xFF0000 : 0x00FF00; var boardLine = gameInstance.lines.find(function (l) { return l.col === line.col && l.row === line.row; }); if (boardLine) { boardLine.isSet = true; } currentPlayer = currentPlayer === 1 ? 2 : 1; checkSquares(gameInstance); updatePlayerIcons(gameInstance, playerNumber); } } var currentPlayer = 1; var player2Score = 0; var player1Score = 0; var Game = Container.expand(function () { var self = Container.call(this); var dots = []; var squares = []; var lines = []; var player1Icon, player2Icon; var boardSize = 6 * 300; var offsetX = (2048 - boardSize) / 2; var offsetY = (2732 - boardSize) / 2 + 150; self.player1Icon = self.addChild(new PlayerIcon(1)); self.player1Icon.x = 2048 * 0.25; self.player1Icon.y = 250; self.player1Icon.scale.set(1.2); var player1ScoreText = new Text2('0', { size: 200, fill: "#ffffff", anchor: { x: 0.5, y: 0 } }); player1ScoreText.x = self.player1Icon.x + self.player1Icon.width / 2 + 80; player1ScoreText.y = 150; self.addChild(player1ScoreText); self.player2Icon = self.addChild(new PlayerIcon(2)); self.player2Icon.x = 2048 * 0.75; self.player2Icon.y = 250; self.player2Icon.scale.set(1); var player2ScoreText = new Text2('0', { size: 200, fill: "#ffffff", anchor: { x: 0.5, y: 0 } }); player2ScoreText.x = self.player2Icon.x - self.player2Icon.width / 2 - 80 - player2ScoreText.width; player2ScoreText.y = 150; self.addChild(player2ScoreText); player1Icon = self.player1Icon; player2Icon = self.player2Icon; for (var i = 0; i < 13; i++) { for (var j = 0; j < 13; j++) { if (i % 2 == 0 && j % 2 != 0) { var hLine = new Line(i, j, true, self); hLine.x = j / 2 * 300; hLine.y = offsetY + i / 2 * 300; hLine.setLength(300); self.addChild(hLine); console.log("A) " + i + "," + j + " => " + hLine.x + "," + hLine.y); boardLine = new BoardLine(i, j); lines.push(boardLine); } if (i % 2 != 0 && j % 2 == 0) { var vLine = new Line(i, j, false, self); vLine.x = offsetX + j / 2 * 300; vLine.y = offsetY * 0.75 + i / 2 * 300; vLine.setLength(300); self.addChild(vLine); console.log("B) " + i + "," + j + " => " + vLine.x + "," + vLine.y); boardLine = new BoardLine(i, j); lines.push(boardLine); } } } self.lines = lines; var boxes = []; for (var i = 0; i < 6; i++) { for (var j = 0; j < 6; j++) { var topLine = lines.find(line => line.row === i * 2 && line.col === 1 + j * 2); var bottomLine = lines.find(line => line.row === i * 2 + 2 && line.col === 1 + j * 2); var leftLine = lines.find(line => line.row === 1 + i * 2 && line.col === j * 2); var rightLine = lines.find(line => line.row === 1 + i * 2 && line.col === j * 2 + 2); var box = new BoardBox(i, j, [topLine, rightLine, bottomLine, leftLine]); boxes.push(box); } } for (var i = 0; i < 7; i++) { for (var j = 0; j < 7; j++) { var dot = new Dot(); var boardLine = null; dot.x = offsetX + i * 300; dot.y = offsetY + j * 300; dots.push(dot); self.addChild(dot); } } self.boxes = boxes; });
===================================================================
--- original.js
+++ change.js
@@ -46,20 +46,22 @@
playerIconGraphics.tint = playerNumber === 2 ? 0x00FF00 : playerIconGraphics.tint;
playerIconGraphics.tint = playerNumber === 1 ? 0xFF0000 : playerIconGraphics.tint;
return self;
});
-function BoardLine(row, col, isSet) {
+function BoardLine(row, col) {
this.col = col;
this.row = row;
- this.isSet = isSet;
+ this.isSet = false;
}
function BoardBox(row, col, borderLines) {
this.col = col;
this.row = row;
this.top = borderLines[0];
this.right = borderLines[1];
this.bottom = borderLines[2];
this.left = borderLines[3];
+ this.isFilled = false;
+ this.playerFilled = 0;
}
function checkSquares(gameInstance) {
console.log('Checking squares for completion', gameInstance.lines);
}
@@ -137,9 +139,9 @@
hLine.y = offsetY + i / 2 * 300;
hLine.setLength(300);
self.addChild(hLine);
console.log("A) " + i + "," + j + " => " + hLine.x + "," + hLine.y);
- boardLine = new BoardLine(i, j, false);
+ boardLine = new BoardLine(i, j);
lines.push(boardLine);
}
if (i % 2 != 0 && j % 2 == 0) {
var vLine = new Line(i, j, false, self);
@@ -147,9 +149,9 @@
vLine.y = offsetY * 0.75 + i / 2 * 300;
vLine.setLength(300);
self.addChild(vLine);
console.log("B) " + i + "," + j + " => " + vLine.x + "," + vLine.y);
- boardLine = new BoardLine(i, j, false);
+ boardLine = new BoardLine(i, j);
lines.push(boardLine);
}
}
}
a b&w grinch icon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
b&w smiling Santa Clauss' head icon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a white christmas star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top face of a white gift. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.