User prompt
define when it is the player turn
User prompt
Fix Bug: 'ReferenceError: playerTurn is not defined' in this line: 'if (playerTurn === 'black' && self.state === 'empty' && isValidMove(i, j, 'black', board)) {' Line Number: 20
User prompt
Fix Bug: 'ReferenceError: playerTurn is not defined' in this line: 'if (playerTurn === 'black' && self.state === 'empty' && isValidMove(i, j, 'black', board)) {' Line Number: 20
User prompt
Fix Bug: 'ReferenceError: boardStartX is not defined' in this line: 'var i = Math.floor((pos.x - boardStartX) / self.width);' Line Number: 18
User prompt
Fix Bug: 'ReferenceError: boardStartX is not defined' in this line: 'var i = Math.floor((pos.x - boardStartX) / self.width);' Line Number: 18
User prompt
Fix Bug: 'Uncaught TypeError: self.setInteractive is not a function' in this line: 'self.setInteractive(true);' Line Number: 16
User prompt
place a new tile on click if the move is valid
User prompt
add a tile when the player clicks on a valid square
User prompt
place starter tiles in the four centre squares
User prompt
create a white tile asset for the AI
User prompt
create a black tile asset for the player
User prompt
create a black tile for the player
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'width')' in this line: 'var boardWidth = 8 * tile.width;' Line Number: 17
User prompt
centre the board on screen
User prompt
Fix Bug: 'Uncaught TypeError: tileGraphics.lineStyle is not a function' in this line: 'tileGraphics.lineStyle(2, 0x000000);' Line Number: 8
User prompt
make the board 8x8, green with black outlines on each square
Initial prompt
Reversi
var AI = function () {
this.makeMove = function (board) {};
};
var Tile = Container.expand(function () {
var self = Container.call(this);
var tileGraphics = self.createAsset('tile', 'Game Tile', .5, .5);
self.state = 'empty';
self.flip = function (newState) {
self.state = newState;
if (self.state === 'black') {
self.createAsset('blackTile', 'Black Tile', .5, .5);
} else if (self.state === 'white') {
self.createAsset('whiteTile', 'White Tile', .5, .5);
}
};
self.on('down', function (obj) {
var pos = obj.event.getLocalPosition(self.parent);
var i = Math.floor((pos.x - self.parent.boardStartX) / self.width);
var j = Math.floor((pos.y - self.parent.boardStartY) / self.height);
if (playerTurn === 'black' && self.state === 'empty' && isValidMove(i, j, 'black', board)) {
self.flip('black');
}
});
});
var Game = Container.expand(function () {
var self = Container.call(this);
var board = [];
var ai = new AI();
var playerTurn = 'black';
var tile = new Tile();
var boardWidth = 8 * tile.width;
var boardHeight = 8 * tile.height;
var boardStartX = (2048 - boardWidth) / 2;
var boardStartY = (2732 - boardHeight) / 2;
var boardStartX = (2048 - boardWidth) / 2;
var boardStartY = (2732 - boardHeight) / 2;
for (var i = 0; i < 8; i++) {
board[i] = [];
for (var j = 0; j < 8; j++) {
var tile = self.addChild(new Tile());
tile.x = boardStartX + i * tile.width;
tile.y = boardStartY + j * tile.height;
board[i][j] = tile;
tile.on('down', function (obj) {
if (playerTurn === 'black' && tile.state === 'empty' && isValidMove(i, j, 'black', board)) {
tile.flip('black');
}
});
}
}
board[3][3].flip('white');
board[3][4].flip('black');
board[4][3].flip('black');
board[4][4].flip('white');
ai.makeMove(board);
function isValidMove(x, y, color, board) {
var dx, dy, x1, y1, count;
for (dx = -1; dx <= 1; dx++) {
for (dy = -1; dy <= 1; dy++) {
x1 = x + dx;
y1 = y + dy;
count = 0;
while (x1 >= 0 && x1 < 8 && y1 >= 0 && y1 < 8 && board[x1][y1].state !== 'empty' && board[x1][y1].state !== color) {
count++;
x1 += dx;
y1 += dy;
}
if (count > 0 && x1 >= 0 && x1 < 8 && y1 >= 0 && y1 < 8 && board[x1][y1].state === color) {
return true;
}
}
}
return false;
}
LK.on('tick', function () {});
});
===================================================================
--- original.js
+++ change.js
@@ -18,17 +18,16 @@
var i = Math.floor((pos.x - self.parent.boardStartX) / self.width);
var j = Math.floor((pos.y - self.parent.boardStartY) / self.height);
if (playerTurn === 'black' && self.state === 'empty' && isValidMove(i, j, 'black', board)) {
self.flip('black');
- playerTurn = 'white';
- ai.makeMove(board);
}
});
});
var Game = Container.expand(function () {
var self = Container.call(this);
var board = [];
var ai = new AI();
+ var playerTurn = 'black';
var tile = new Tile();
var boardWidth = 8 * tile.width;
var boardHeight = 8 * tile.height;
var boardStartX = (2048 - boardWidth) / 2;
@@ -44,10 +43,8 @@
board[i][j] = tile;
tile.on('down', function (obj) {
if (playerTurn === 'black' && tile.state === 'empty' && isValidMove(i, j, 'black', board)) {
tile.flip('black');
- playerTurn = 'white';
- ai.makeMove(board);
}
});
}
}
create a flat, round, black counter. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
create a flat, round, white counter. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
create a flat green square with sharp corners and a very thin darker outline Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.