User prompt
in the game class, rather than calling all the init methods just call the reset board method that does the same
User prompt
In game create a reset board method
User prompt
Also assume fixed cell width and hight in board ondown
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.cells[cellX][cellY]')' in this line: 'var cell = self.cells[cellX][cellY];' Line Number: 93
User prompt
Assume cells are 180x180px
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.cells[cellX][cellY]')' in this line: 'var cell = self.cells[cellX][cellY];' Line Number: 94
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.cells[cellX][cellY]')' in this line: 'var cell = self.cells[cellX][cellY];' Line Number: 94
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'cell.isRevealed')' in this line: 'if (!cell.isRevealed) {' Line Number: 105
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.cells[cellX][cellY]')' in this line: 'var cell = self.cells[cellX][cellY];' Line Number: 93
User prompt
When clicking a cell, if the cell has zero neighbors mines. Reveal its neighbors. Do this recursively.
User prompt
In number title use => 1 to determine if the node has a label
User prompt
If a number tile has more than 1 neighbor, add a label to the tile showing how many neighbors the tile has.
User prompt
in cell, you can't use .x .y to calculate calculateNeighborMines as these are pixel positions. Instead cache the values given to the cell in setPosition and use those variables
Code edit (2 edits merged)
Please save this source code
User prompt
In the sell set position, offset x,y by half the cell width to compensate for the cell's anchor point
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.cells[cellX][cellY]')' in this line: 'var cell = self.cells[cellX][cellY];' Line Number: 53
Code edit (1 edits merged)
Please save this source code
User prompt
When I click the board it sometimes selects the wrong mine. I think this is because you do not factor in that cells have anchor points at .5,.5
User prompt
Move down handler from self to board in game
User prompt
Fix Bug: 'ReferenceError: Can't find variable: Mine' in this line: 'var mine = new Mine();' Line Number: 20
User prompt
Call place mines with 10
var Mine = Container.expand(function () { var self = Container.call(this); var mineGraphics = self.createAsset('mine', 'Mine Graphics', .5, .5); }); var NumberTile = Container.expand(function (number) { var self = Container.call(this); var numberGraphics = self.createAsset('number_' + number, 'Number ' + number + ' Graphics', .5, .5); }); var Cell = Container.expand(function () { var self = Container.call(this); self.setPosition = function (x, y) { self.x = x * self.width; self.y = y * self.height; }; 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.visible = false; var mine = self.addChild(new Mine()); } else { cellGraphics.visible = false; var number = self.addChild(new NumberTile(self.neighborMines)); self.addChild(number); } }; 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); self.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); var cellX = Math.floor(pos.x / self.cells[0][0].width); var cellY = Math.floor(pos.y / self.cells[0][0].height); self.onCellClicked(cellX, cellY); }); self.onCellClicked = function (cellX, cellY) { var cell = self.cells[cellX][cellY]; if (!cell.isRevealed) { cell.reveal(); if (cell.isMine) { gameOver = true; self.revealAllMines(); LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } }; self.revealAllMines = function () { for (var x = 0; x < self.cells.length; x++) { for (var y = 0; y < self.cells[x].length; y++) { var cell = self.cells[x][y]; if (cell.isMine) { cell.reveal(); } } } }; 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(); self.addChild(cell); self.cells[x][y] = cell; cell.setPosition(x, y); } } }; 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]; if (!cell.isRevealed) { 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(10, 10); board.placeMines(10); board.calculateAllNeighborMines(); });
===================================================================
--- original.js
+++ change.js
@@ -42,8 +42,14 @@
};
});
var Board = Container.expand(function () {
var self = Container.call(this);
+ self.on('down', function (obj) {
+ var pos = obj.event.getLocalPosition(self);
+ var cellX = Math.floor(pos.x / self.cells[0][0].width);
+ var cellY = Math.floor(pos.y / self.cells[0][0].height);
+ self.onCellClicked(cellX, cellY);
+ });
self.onCellClicked = function (cellX, cellY) {
var cell = self.cells[cellX][cellY];
if (!cell.isRevealed) {
cell.reveal();
@@ -124,11 +130,5 @@
var gameOver = false;
board.generateBoard(10, 10);
board.placeMines(10);
board.calculateAllNeighborMines();
- self.on('down', function (obj) {
- var pos = obj.event.getLocalPosition(board);
- var cellX = Math.floor(pos.x / board.cells[0][0].width);
- var cellY = Math.floor(pos.y / board.cells[0][0].height);
- board.onCellClicked(cellX, cellY);
- });
});
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.