User prompt
Fix Bug: 'ReferenceError: Can't find variable: updateScores' in this line: 'updateScores(gameInstance, player1ScoreText, player2ScoreText);' Line Number: 82
User prompt
Fix Bug: 'ReferenceError: Can't find variable: updateScores' in this line: 'updateScores(gameInstance);' Line Number: 82
User prompt
Fix Bug: 'ReferenceError: Can't find variable: updateScores' in this line: 'updateScores(gameInstance);' Line Number: 82
User prompt
Fix Bug: 'ReferenceError: Can't find variable: updateScores' in this line: 'updateScores(gameInstance);' Line Number: 82
User prompt
Fix Bug: 'ReferenceError: Can't find variable: updateScores' in this line: 'updateScores(gameInstance);' Line Number: 82
User prompt
Fix Bug: 'ReferenceError: Can't find variable: updateScores' in this line: 'updateScores(gameInstance);' Line Number: 78
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.squares')' in this line: 'if (coordinates.row < 6) squaresToCheck.push(self.squares[coordinates.row * 6 + coordinates.col]);' Line Number: 61
User prompt
Fix Bug: 'ReferenceError: Can't find variable: lines' in this line: 'lines.push(hLine);' Line Number: 155
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'gameInstance.lines.forEach')' in this line: 'gameInstance.lines.forEach(function (line) {' Line Number: 55
User prompt
No, checkSquares should browse lines not squares variable
User prompt
In checkSquares browse the lines array to determine full squares
User prompt
Add gameinstance param in checksquares
User prompt
In activateLine pass the gameinstance to checkSquares
User prompt
Remove squares loop from tick event
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.squares.forEach')' in this line: 'self.squares.forEach(function (square) {' Line Number: 157
User prompt
Fix Bug: 'ReferenceError: Can't find variable: squares' in this line: 'squares.forEach(function (square) {' Line Number: 156
User prompt
Fix Bug: 'ReferenceError: Can't find variable: lines' in this line: 'lines.push(hLine);' Line Number: 130
User prompt
Fix Bug: 'Uncaught ReferenceError: dots is not defined' in this line: 'dots.push(dot);' Line Number: 119
User prompt
move the lines array to global scope near currentPlayer
User prompt
add a global function checkSquares with just a console log and call it in activateLine
User prompt
clean HorizontalLine code from old unused coordinates
User prompt
change coordinates to only store row and col
User prompt
create an array of objects to keep track of the lines. object should store coordinates, and status of the line
User prompt
create the squares
User prompt
implement square.isComplete()
var VerticalLine = Container.expand(function (playerNumber, gameInstance) { var self = Container.call(this); var lineGraphics = self.createAsset('lineVertical', 'Vertical Line Graphics', 0.5, 0); lineGraphics.alpha = 0.3; self.playerNumber = null; self.gameInstance = gameInstance; self.setLength = function (length) { lineGraphics.height = length; }; self.on('down', function () { activateLine(self, currentPlayer, lineGraphics, self.gameInstance); }); return self; }); var HorizontalLine = Container.expand(function (playerNumber, gameInstance) { var self = Container.call(this); var lineGraphics = self.createAsset('lineHorizontal', 'Horizontal Line Graphics', 0, 0.5); lineGraphics.alpha = 0.3; self.status = 'inactive'; self.playerNumber = null; self.gameInstance = gameInstance; self.setLength = function (length) { lineGraphics.width = length; }; self.on('down', function () { activateLine(self, currentPlayer, lineGraphics, self.gameInstance); }); 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 checkSquares() { console.log('Checking squares for completion'); } function updatePlayerIcons(currentPlayer, player1Icon, player2Icon) { if (player1Icon && player2Icon) { player1Icon.scale.set(currentPlayer === 1 ? 1.2 : 0.8); player2Icon.scale.set(currentPlayer === 2 ? 1.2 : 0.8); } } function activateLine(line, playerNumber, lineGraphics, gameInstance) { if (line.playerNumber === null) { line.playerNumber = playerNumber; lineGraphics.alpha = 1; lineGraphics.tint = playerNumber === 1 ? 0xFF0000 : 0x00FF00; currentPlayer = currentPlayer === 1 ? 2 : 1; checkSquares(gameInstance); updatePlayerIcons(playerNumber, gameInstance.player1Icon, gameInstance.player2Icon); } } var currentPlayer = 1; this.player2Score = 0; this.player1Score = 0; var Game = Container.expand(function () { var self = Container.call(this); var dots = []; var lines = []; self.squares = []; 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; var player1Icon, player2Icon; var boardSize = 6 * 300; var offsetX = (2048 - boardSize) / 2; var offsetY = (2732 - boardSize) / 2 + 150; for (var i = 0; i < 7; i++) { for (var j = 0; j < 7; j++) { var dot = new Dot(); dot.x = offsetX + i * 300; dot.y = offsetY + j * 300; dots.push(dot); if (i < 6) { var hLine = new HorizontalLine(currentPlayer, self); hLine.x = dot.x; hLine.y = dot.y; hLine.setLength(300); hLine.coordinates = { row: j, col: i }; lines.push(hLine); self.addChild(hLine); } if (j < 6) { var vLine = new VerticalLine(currentPlayer, self); vLine.x = dot.x; vLine.y = dot.y; vLine.setLength(300); vLine.coordinates = { row: j, col: i }; lines.push(vLine); self.addChild(vLine); } self.addChild(dot); } } dots.forEach(function (dot) { dot.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); }); }); });
===================================================================
--- original.js
+++ change.js
@@ -65,9 +65,9 @@
line.playerNumber = playerNumber;
lineGraphics.alpha = 1;
lineGraphics.tint = playerNumber === 1 ? 0xFF0000 : 0x00FF00;
currentPlayer = currentPlayer === 1 ? 2 : 1;
- checkSquares();
+ checkSquares(gameInstance);
updatePlayerIcons(playerNumber, gameInstance.player1Icon, gameInstance.player2Icon);
}
}
var currentPlayer = 1;
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.