User prompt
Call place mines with 10
User prompt
Fix Bug: 'ReferenceError: Can't find variable: NumberTile' in this line: 'var number = new NumberTile(self.neighborMines);' Line Number: 20
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'this.scale.y')' in this line: 'var cellY = Math.floor(pos.y / Cell.prototype.height);' Line Number: 124
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'this.scale.x')' in this line: 'var cellX = Math.floor(pos.x / Cell.prototype.width);' Line Number: 123
User prompt
Progress the development of the game please
User prompt
You can’t change texture in LK please just hide exciting backgound and show another asset. Use a label to show the mine state
User prompt
Fix Bug: 'TypeError: cellGraphics.setTexture is not a function. (In 'cellGraphics.setTexture('number_' + self.neighborMines)', 'cellGraphics.setTexture' is undefined)' in this line: 'cellGraphics.setTexture('number_' + self.neighborMines);' Line Number: 17
User prompt
Fix Bug: 'ReferenceError: Can't find variable: cellGraphics' in this line: 'var cellX = Math.floor(pos.x / cellGraphics.width);' Line Number: 107
User prompt
Fix Bug: 'ReferenceError: Can't find variable: cellGraphics' in this line: 'cell.x = x * cellGraphics.width;' Line Number: 48
User prompt
Progress the development of the game please
User prompt
Progress the development of the game please
Initial prompt
Minesweeper
var Cell = Container.expand(function () {
var self = Container.call(this);
var cellGraphics = self.createAsset('cell', 'Cell Graphics', .5, .5);
self.isMine = false;
self.isRevealed = false;
self.neighborMines = 0;
self.reveal = function () {
if (self.isRevealed) return;
self.isRevealed = true;
if (self.isMine) {
cellGraphics.setTexture('mine');
} else {
cellGraphics.setTexture('number_' + self.neighborMines);
}
};
self.placeMine = function () {
self.isMine = true;
};
self.calculateNeighborMines = function (getNeighbor) {
self.neighborMines = 0;
var neighbors = getNeighbor(self.x, self.y);
for (var i = 0; i < neighbors.length; i++) {
if (neighbors[i].isMine) {
self.neighborMines++;
}
}
};
});
var Board = Container.expand(function () {
var self = Container.call(this);
var boardGraphics = self.createAsset('board', 'Board Graphics', .5, .5);
self.cells = [];
self.generateBoard = function (width, height) {
for (var x = 0; x < width; x++) {
self.cells[x] = [];
for (var y = 0; y < height; y++) {
var cell = new Cell();
cell.x = x * cellGraphics.width;
cell.y = y * cellGraphics.height;
self.addChild(cell);
self.cells[x][y] = cell;
}
}
};
self.revealCell = function (x, y) {
if (x < 0 || x >= self.cells.length || y < 0 || y >= self.cells[x].length) return;
var cell = self.cells[x][y];
cell.reveal();
return cell.isMine;
};
self.placeMines = function (mineCount) {
var placedMines = 0;
while (placedMines < mineCount) {
var x = Math.floor(Math.random() * self.cells.length);
var y = Math.floor(Math.random() * self.cells[x].length);
if (!self.cells[x][y].isMine) {
self.cells[x][y].placeMine();
placedMines++;
}
}
};
self.calculateAllNeighborMines = function () {
var getNeighbor = function (x, y) {
var neighbors = [];
for (var dx = -1; dx <= 1; dx++) {
for (var dy = -1; dy <= 1; dy++) {
if (dx === 0 && dy === 0) continue;
var nx = x + dx, ny = y + dy;
if (nx >= 0 && nx < self.cells.length && ny >= 0 && ny < self.cells[nx].length) {
neighbors.push(self.cells[nx][ny]);
}
}
}
return neighbors;
};
for (var x = 0; x < self.cells.length; x++) {
for (var y = 0; y < self.cells[x].length; y++) {
self.cells[x][y].calculateNeighborMines(getNeighbor);
}
}
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var board = self.addChild(new Board());
var gameOver = false;
board.generateBoard();
board.placeMines();
board.calculateAllNeighborMines();
self.on('down', function (obj) {
var pos = obj.event.getLocalPosition(self);
var cellX = Math.floor(pos.x / cellGraphics.width);
var cellY = Math.floor(pos.y / cellGraphics.height);
board.revealCell(cellX, cellY);
if (board.cells[cellX][cellY].isMine) {
gameOver = true;
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
LK.on('tick', function () {
if (gameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
});
===================================================================
--- original.js
+++ change.js
@@ -3,20 +3,83 @@
var cellGraphics = self.createAsset('cell', 'Cell Graphics', .5, .5);
self.isMine = false;
self.isRevealed = false;
self.neighborMines = 0;
- self.reveal = function () {};
- self.placeMine = function () {};
- self.calculateNeighborMines = function () {};
+ self.reveal = function () {
+ if (self.isRevealed) return;
+ self.isRevealed = true;
+ if (self.isMine) {
+ cellGraphics.setTexture('mine');
+ } else {
+ cellGraphics.setTexture('number_' + self.neighborMines);
+ }
+ };
+ self.placeMine = function () {
+ self.isMine = true;
+ };
+ self.calculateNeighborMines = function (getNeighbor) {
+ self.neighborMines = 0;
+ var neighbors = getNeighbor(self.x, self.y);
+ for (var i = 0; i < neighbors.length; i++) {
+ if (neighbors[i].isMine) {
+ self.neighborMines++;
+ }
+ }
+ };
});
var Board = Container.expand(function () {
var self = Container.call(this);
var boardGraphics = self.createAsset('board', 'Board Graphics', .5, .5);
self.cells = [];
- self.generateBoard = function () {};
- self.revealCell = function (x, y) {};
- self.placeMines = function () {};
- self.calculateAllNeighborMines = function () {};
+ self.generateBoard = function (width, height) {
+ for (var x = 0; x < width; x++) {
+ self.cells[x] = [];
+ for (var y = 0; y < height; y++) {
+ var cell = new Cell();
+ cell.x = x * cellGraphics.width;
+ cell.y = y * cellGraphics.height;
+ self.addChild(cell);
+ self.cells[x][y] = cell;
+ }
+ }
+ };
+ self.revealCell = function (x, y) {
+ if (x < 0 || x >= self.cells.length || y < 0 || y >= self.cells[x].length) return;
+ var cell = self.cells[x][y];
+ cell.reveal();
+ return cell.isMine;
+ };
+ self.placeMines = function (mineCount) {
+ var placedMines = 0;
+ while (placedMines < mineCount) {
+ var x = Math.floor(Math.random() * self.cells.length);
+ var y = Math.floor(Math.random() * self.cells[x].length);
+ if (!self.cells[x][y].isMine) {
+ self.cells[x][y].placeMine();
+ placedMines++;
+ }
+ }
+ };
+ self.calculateAllNeighborMines = function () {
+ var getNeighbor = function (x, y) {
+ var neighbors = [];
+ for (var dx = -1; dx <= 1; dx++) {
+ for (var dy = -1; dy <= 1; dy++) {
+ if (dx === 0 && dy === 0) continue;
+ var nx = x + dx, ny = y + dy;
+ if (nx >= 0 && nx < self.cells.length && ny >= 0 && ny < self.cells[nx].length) {
+ neighbors.push(self.cells[nx][ny]);
+ }
+ }
+ }
+ return neighbors;
+ };
+ for (var x = 0; x < self.cells.length; x++) {
+ for (var y = 0; y < self.cells[x].length; y++) {
+ self.cells[x][y].calculateNeighborMines(getNeighbor);
+ }
+ }
+ };
});
var Game = Container.expand(function () {
var self = Container.call(this);
var board = self.addChild(new Board());
Sea mine. Minesweeper. Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Watery background. 10x10 Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single white square. Round corners. Vector. Simple details. Flat shaded. No shadows. No outlines.