User prompt
Rotate the NumberTile graphics by 180
User prompt
Rotate cellGraphics by 180 deg
User prompt
Set background color on game to 89a6bb
User prompt
In number tile set numberGraphics alpha to zero when number is zero
User prompt
in NumberTile set numberGraphics alpha to .2 if number is zero
User prompt
set boardGraphics anchor to 0,0
User prompt
You can't read the value of a label, instead set a score variable on game and use that
User prompt
You can't read the value of a label, instead set a score variable on game and use that
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: parseInt is not a function. (In 'parseInt(self.parent.parent.scoreTxt.text)', 'parseInt' is undefined)' in this line: 'self.parent.parent.scoreTxt.setText(parseInt(self.parent.parent.scoreTxt.text) + 1);' Line Number: 46
User prompt
Fix Bug: 'TypeError: self.getGame is not a function. (In 'self.getGame()', 'self.getGame' is undefined)' in this line: 'self.getGame().scoreTxt.setText(parseInt(self.getGame().scoreTxt.text) + 1);' Line Number: 46
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self.parent.scoreTxt.setText')' in this line: 'self.parent.scoreTxt.setText(parseInt(self.parent.scoreTxt.text) + 1);' Line Number: 46
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'Game.scoreTxt.setText')' in this line: 'Game.scoreTxt.setText(parseInt(Game.scoreTxt.text) + 1);' Line Number: 46
User prompt
Fix Bug: 'ReferenceError: Can't find variable: scoreTxt' in this line: 'scoreTxt.setText(parseInt(scoreTxt.text) + 1);' Line Number: 46
User prompt
Fix Bug: 'TypeError: LK.gui.topCenter.getChildByName is not a function. (In 'LK.gui.topCenter.getChildByName('scoreTxt')', 'LK.gui.topCenter.getChildByName' is undefined)' in this line: 'LK.gui.topCenter.getChildByName('scoreTxt').setText(parseInt(LK.gui.topCenter.getChildByName('scoreTxt').text) + 1);' Line Number: 46
User prompt
For each tile revealed, increase score by 1
User prompt
Add a score label to the game at the top center
User prompt
When reset board is called, write "Level $X" at the center of the board for 1 sec
User prompt
The board should keep track of how many times resetBoard has been called and use that to increase how many mines are placed each time it's called
User prompt
In Board increase how many mines are placed each time resetBoard is called
User prompt
For number tile labels, set weight:800
User prompt
text only support string fills. Just make it white and use tint to color the label
User prompt
Instead of coloring the numberGraphics color the label
User prompt
Only add 5 mines to the board
User prompt
do not set a timeout around show game over
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 tileType = number === 0 ? 'number_0' : 'number_other'; var numberGraphics = self.createAsset(tileType, 'Number Tile Graphics', .5, .5); if (number >= 1) { var dangerColors = [0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff, 0xff0000, 0x9900ff, 0xff9900]; var label = new Text2(number.toString(), { size: 100, fill: '#ffffff', align: 'center', weight: 800 }); label.anchor.set(0.5); label.tint = dangerColors[number - 1]; self.addChild(label); } }); var Cell = Container.expand(function () { var self = Container.call(this); self.gridX = 0; self.gridY = 0; self.setPosition = function (x, y) { self.gridX = x; self.gridY = y; self.x = x * 180 + 90; self.y = y * 180 + 90; }; 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.parent.scoreTxt.setText(parseInt(self.parent.scoreTxt.text) + 1); } }; self.placeMine = function () { self.isMine = true; }; self.calculateNeighborMines = function (getNeighbor) { self.neighborMines = 0; var neighbors = getNeighbor(self.gridX, self.gridY); 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.resetBoard = function () { for (var x = 0; x < self.cells.length; x++) { for (var y = 0; y < self.cells[x].length; y++) { self.cells[x][y].destroy(); } } self.cells = []; self.generateBoard(10, 10); self.placeMines(5 + self.resetCount); self.calculateAllNeighborMines(); self.resetCount++; var totalWidth = self.cells.length * 180; var totalHeight = self.cells[0].length * 180; self.x = (2048 - totalWidth) / 2; self.y = (2732 - totalHeight) / 2; var levelText = new Text2('Level ' + self.resetCount, { size: 150, fill: '#ffffff', align: 'center', weight: 800 }); levelText.anchor.set(0.5); levelText.x = totalWidth / 2; levelText.y = totalHeight / 2; self.addChild(levelText); LK.setTimeout(function () { levelText.destroy(); }, 1000); }; self.getNeighbors = 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; }; self.revealCellAndNeighbors = 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 && !cell.isRevealed) { cell.reveal(); if (cell.neighborMines === 0) { var neighbors = self.getNeighbors(x, y); for (var i = 0; i < neighbors.length; i++) { var neighbor = neighbors[i]; if (Math.abs(neighbor.gridX - x) + Math.abs(neighbor.gridY - y) === 1) { self.revealCellAndNeighbors(neighbor.gridX, neighbor.gridY); } } } } }; self.on('down', function (obj) { var pos = obj.event.getLocalPosition(self); var cellX = Math.floor(pos.x / 180); var cellY = Math.floor(pos.y / 180); self.onCellClicked(cellX, cellY); }); self.onCellClicked = function (cellX, cellY) { if (cellX >= 0 && cellX < self.cells.length && cellY >= 0 && cellY < self.cells[cellX].length) { var cell = self.cells[cellX][cellY]; } if (cell && !cell.isRevealed) { if (cell.isMine && !self.firstClick) { self.firstClick = true; cell.isMine = false; var randomX, randomY, randomCell; do { randomX = Math.floor(Math.random() * self.cells.length); randomY = Math.floor(Math.random() * self.cells[randomX].length); randomCell = self.cells[randomX][randomY]; } while (randomCell.isMine); randomCell.placeMine(); self.calculateAllNeighborMines(); } self.revealCellAndNeighbors(cellX, cellY); self.firstClick = true; if (cell.isMine) { gameOver = true; self.revealAllMines(); LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else { var unrevealedCells = 0; var mineCells = 0; for (var x = 0; x < self.cells.length; x++) { for (var y = 0; y < self.cells[x].length; y++) { if (!self.cells[x][y].isRevealed) { unrevealedCells++; if (self.cells[x][y].isMine) { mineCells++; } } } } if (unrevealedCells === mineCells) { LK.effects.flashScreen(0x00ff00, 1000); self.resetBoard(); } } } }; 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.firstClick = false; self.resetCount = 0; 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); self.scoreTxt = new Text2('0', { size: 150, fill: '#ffffff' }); self.scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(self.scoreTxt); var board = self.addChild(new Board()); var gameOver = false; board.resetBoard(); });
===================================================================
--- original.js
+++ change.js
@@ -42,9 +42,9 @@
} else {
cellGraphics.visible = false;
var number = self.addChild(new NumberTile(self.neighborMines));
self.addChild(number);
- Game.scoreTxt.setText(parseInt(Game.scoreTxt.text) + 1);
+ self.parent.scoreTxt.setText(parseInt(self.parent.scoreTxt.text) + 1);
}
};
self.placeMine = function () {
self.isMine = true;
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.