/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var MineTile = Container.expand(function (row, col) {
var self = Container.call(this);
self.row = row;
self.col = col;
self.isMine = false;
self.isRevealed = false;
self.isFlagged = false;
self.adjacentMines = 0;
var tileGraphics = self.attachAsset('tile', {
anchorX: 0,
anchorY: 0
});
var numberText = new Text2('', {
size: 60,
fill: 0x000000
});
numberText.anchor.set(0.5, 0.5);
numberText.x = 60;
numberText.y = 60;
self.addChild(numberText);
self.numberText = numberText;
self.tileGraphics = tileGraphics;
self.setMine = function () {
self.isMine = true;
};
self.setAdjacentMines = function (count) {
self.adjacentMines = count;
};
self.reveal = function () {
if (self.isRevealed || self.isFlagged) return false;
self.isRevealed = true;
if (self.isMine) {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('mineTile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
self.numberText.setText('💣');
LK.getSound('explosion').play();
return false;
} else {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('revealedTile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
if (self.adjacentMines > 0) {
self.numberText.setText(self.adjacentMines.toString());
var colors = ['', '#0000ff', '#008000', '#ff0000', '#800080', '#800000', '#008080', '#000000', '#808080'];
self.numberText.fill = colors[self.adjacentMines] || '#000000';
}
LK.getSound('tileReveal').play();
return true;
}
};
self.toggleFlag = function () {
if (self.isRevealed) return;
self.isFlagged = !self.isFlagged;
if (self.isFlagged) {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('flagTile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
self.numberText.setText('🚩');
LK.getSound('flag').play();
} else {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('tile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
self.numberText.setText('');
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x888888
});
/****
* Game Code
****/
var GRID_WIDTH = 12;
var GRID_HEIGHT = 15;
var MINE_COUNT = 30;
var TILE_SIZE = 120;
var TILE_SPACING = 0;
var grid = [];
var gameBoard;
var gameStarted = false;
var gameOver = false;
var isVictory = false;
var tilesRevealed = 0;
var totalSafeTiles;
var pressStartTime = 0;
var longPressThreshold = 500;
var currentPressedTile = null;
function initializeGrid() {
grid = [];
gameBoard = new Container();
game.addChild(gameBoard);
var boardWidth = GRID_WIDTH * (TILE_SIZE + TILE_SPACING) - TILE_SPACING;
var boardHeight = GRID_HEIGHT * (TILE_SIZE + TILE_SPACING) - TILE_SPACING;
gameBoard.x = (2048 - boardWidth) / 2;
gameBoard.y = (2732 - boardHeight) / 2;
for (var row = 0; row < GRID_HEIGHT; row++) {
grid[row] = [];
for (var col = 0; col < GRID_WIDTH; col++) {
var tile = new MineTile(row, col);
tile.x = col * (TILE_SIZE + TILE_SPACING);
tile.y = row * (TILE_SIZE + TILE_SPACING);
grid[row][col] = tile;
gameBoard.addChild(tile);
}
}
}
function placeMines(excludeRow, excludeCol) {
var availablePositions = [];
for (var row = 0; row < GRID_HEIGHT; row++) {
for (var col = 0; col < GRID_WIDTH; col++) {
if (!(row === excludeRow && col === excludeCol)) {
availablePositions.push({
row: row,
col: col
});
}
}
}
for (var i = 0; i < MINE_COUNT && availablePositions.length > 0; i++) {
var randomIndex = Math.floor(Math.random() * availablePositions.length);
var pos = availablePositions[randomIndex];
grid[pos.row][pos.col].setMine();
availablePositions.splice(randomIndex, 1);
}
calculateAdjacentMines();
totalSafeTiles = GRID_WIDTH * GRID_HEIGHT - MINE_COUNT;
}
function calculateAdjacentMines() {
for (var row = 0; row < GRID_HEIGHT; row++) {
for (var col = 0; col < GRID_WIDTH; col++) {
if (!grid[row][col].isMine) {
var count = 0;
var startRow = Math.max(0, row - 1);
var endRow = Math.min(GRID_HEIGHT - 1, row + 1);
var startCol = Math.max(0, col - 1);
var endCol = Math.min(GRID_WIDTH - 1, col + 1);
for (var r = startRow; r <= endRow; r++) {
for (var c = startCol; c <= endCol; c++) {
if (r !== row || c !== col) {
if (grid[r][c].isMine) {
count++;
}
}
}
}
grid[row][col].setAdjacentMines(count);
}
}
}
}
function revealTile(row, col) {
if (row < 0 || row >= GRID_HEIGHT || col < 0 || col >= GRID_WIDTH) return;
if (grid[row][col].isRevealed || grid[row][col].isFlagged) return;
var success = grid[row][col].reveal();
if (!success && grid[row][col].isMine) {
gameOver = true;
revealAllMines();
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return;
}
tilesRevealed++;
if (grid[row][col].adjacentMines === 0) {
for (var dr = -1; dr <= 1; dr++) {
for (var dc = -1; dc <= 1; dc++) {
revealTile(row + dr, col + dc);
}
}
}
if (tilesRevealed >= totalSafeTiles) {
isVictory = true;
gameOver = true;
LK.getSound('victory').play();
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
}
}
function revealAllMines() {
for (var row = 0; row < GRID_HEIGHT; row++) {
for (var col = 0; col < GRID_WIDTH; col++) {
var tile = grid[row][col];
if (tile.isMine && !tile.isRevealed) {
tile.reveal();
}
}
}
}
function getTileAt(x, y) {
var boardPos = gameBoard.toLocal({
x: x,
y: y
});
var col = Math.floor(boardPos.x / (TILE_SIZE + TILE_SPACING));
var row = Math.floor(boardPos.y / (TILE_SIZE + TILE_SPACING));
if (row >= 0 && row < GRID_HEIGHT && col >= 0 && col < GRID_WIDTH) {
var tileX = col * (TILE_SIZE + TILE_SPACING);
var tileY = row * (TILE_SIZE + TILE_SPACING);
if (boardPos.x >= tileX && boardPos.x < tileX + TILE_SIZE && boardPos.y >= tileY && boardPos.y < tileY + TILE_SIZE) {
return grid[row][col];
}
}
return null;
}
game.down = function (x, y, obj) {
if (gameOver) return;
var tile = getTileAt(x, y);
if (!tile) return;
pressStartTime = Date.now();
currentPressedTile = tile;
};
game.up = function (x, y, obj) {
if (gameOver || !currentPressedTile) return;
var pressDuration = Date.now() - pressStartTime;
var tile = getTileAt(x, y);
if (tile === currentPressedTile) {
if (pressDuration >= longPressThreshold) {
tile.toggleFlag();
} else {
if (!gameStarted) {
placeMines(tile.row, tile.col);
gameStarted = true;
}
if (!tile.isFlagged) {
revealTile(tile.row, tile.col);
}
}
}
currentPressedTile = null;
};
initializeGrid(); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var MineTile = Container.expand(function (row, col) {
var self = Container.call(this);
self.row = row;
self.col = col;
self.isMine = false;
self.isRevealed = false;
self.isFlagged = false;
self.adjacentMines = 0;
var tileGraphics = self.attachAsset('tile', {
anchorX: 0,
anchorY: 0
});
var numberText = new Text2('', {
size: 60,
fill: 0x000000
});
numberText.anchor.set(0.5, 0.5);
numberText.x = 60;
numberText.y = 60;
self.addChild(numberText);
self.numberText = numberText;
self.tileGraphics = tileGraphics;
self.setMine = function () {
self.isMine = true;
};
self.setAdjacentMines = function (count) {
self.adjacentMines = count;
};
self.reveal = function () {
if (self.isRevealed || self.isFlagged) return false;
self.isRevealed = true;
if (self.isMine) {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('mineTile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
self.numberText.setText('💣');
LK.getSound('explosion').play();
return false;
} else {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('revealedTile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
if (self.adjacentMines > 0) {
self.numberText.setText(self.adjacentMines.toString());
var colors = ['', '#0000ff', '#008000', '#ff0000', '#800080', '#800000', '#008080', '#000000', '#808080'];
self.numberText.fill = colors[self.adjacentMines] || '#000000';
}
LK.getSound('tileReveal').play();
return true;
}
};
self.toggleFlag = function () {
if (self.isRevealed) return;
self.isFlagged = !self.isFlagged;
if (self.isFlagged) {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('flagTile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
self.numberText.setText('🚩');
LK.getSound('flag').play();
} else {
self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('tile', {
anchorX: 0,
anchorY: 0
});
self.addChildAt(self.tileGraphics, 0);
self.numberText.setText('');
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x888888
});
/****
* Game Code
****/
var GRID_WIDTH = 12;
var GRID_HEIGHT = 15;
var MINE_COUNT = 30;
var TILE_SIZE = 120;
var TILE_SPACING = 0;
var grid = [];
var gameBoard;
var gameStarted = false;
var gameOver = false;
var isVictory = false;
var tilesRevealed = 0;
var totalSafeTiles;
var pressStartTime = 0;
var longPressThreshold = 500;
var currentPressedTile = null;
function initializeGrid() {
grid = [];
gameBoard = new Container();
game.addChild(gameBoard);
var boardWidth = GRID_WIDTH * (TILE_SIZE + TILE_SPACING) - TILE_SPACING;
var boardHeight = GRID_HEIGHT * (TILE_SIZE + TILE_SPACING) - TILE_SPACING;
gameBoard.x = (2048 - boardWidth) / 2;
gameBoard.y = (2732 - boardHeight) / 2;
for (var row = 0; row < GRID_HEIGHT; row++) {
grid[row] = [];
for (var col = 0; col < GRID_WIDTH; col++) {
var tile = new MineTile(row, col);
tile.x = col * (TILE_SIZE + TILE_SPACING);
tile.y = row * (TILE_SIZE + TILE_SPACING);
grid[row][col] = tile;
gameBoard.addChild(tile);
}
}
}
function placeMines(excludeRow, excludeCol) {
var availablePositions = [];
for (var row = 0; row < GRID_HEIGHT; row++) {
for (var col = 0; col < GRID_WIDTH; col++) {
if (!(row === excludeRow && col === excludeCol)) {
availablePositions.push({
row: row,
col: col
});
}
}
}
for (var i = 0; i < MINE_COUNT && availablePositions.length > 0; i++) {
var randomIndex = Math.floor(Math.random() * availablePositions.length);
var pos = availablePositions[randomIndex];
grid[pos.row][pos.col].setMine();
availablePositions.splice(randomIndex, 1);
}
calculateAdjacentMines();
totalSafeTiles = GRID_WIDTH * GRID_HEIGHT - MINE_COUNT;
}
function calculateAdjacentMines() {
for (var row = 0; row < GRID_HEIGHT; row++) {
for (var col = 0; col < GRID_WIDTH; col++) {
if (!grid[row][col].isMine) {
var count = 0;
var startRow = Math.max(0, row - 1);
var endRow = Math.min(GRID_HEIGHT - 1, row + 1);
var startCol = Math.max(0, col - 1);
var endCol = Math.min(GRID_WIDTH - 1, col + 1);
for (var r = startRow; r <= endRow; r++) {
for (var c = startCol; c <= endCol; c++) {
if (r !== row || c !== col) {
if (grid[r][c].isMine) {
count++;
}
}
}
}
grid[row][col].setAdjacentMines(count);
}
}
}
}
function revealTile(row, col) {
if (row < 0 || row >= GRID_HEIGHT || col < 0 || col >= GRID_WIDTH) return;
if (grid[row][col].isRevealed || grid[row][col].isFlagged) return;
var success = grid[row][col].reveal();
if (!success && grid[row][col].isMine) {
gameOver = true;
revealAllMines();
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return;
}
tilesRevealed++;
if (grid[row][col].adjacentMines === 0) {
for (var dr = -1; dr <= 1; dr++) {
for (var dc = -1; dc <= 1; dc++) {
revealTile(row + dr, col + dc);
}
}
}
if (tilesRevealed >= totalSafeTiles) {
isVictory = true;
gameOver = true;
LK.getSound('victory').play();
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
}
}
function revealAllMines() {
for (var row = 0; row < GRID_HEIGHT; row++) {
for (var col = 0; col < GRID_WIDTH; col++) {
var tile = grid[row][col];
if (tile.isMine && !tile.isRevealed) {
tile.reveal();
}
}
}
}
function getTileAt(x, y) {
var boardPos = gameBoard.toLocal({
x: x,
y: y
});
var col = Math.floor(boardPos.x / (TILE_SIZE + TILE_SPACING));
var row = Math.floor(boardPos.y / (TILE_SIZE + TILE_SPACING));
if (row >= 0 && row < GRID_HEIGHT && col >= 0 && col < GRID_WIDTH) {
var tileX = col * (TILE_SIZE + TILE_SPACING);
var tileY = row * (TILE_SIZE + TILE_SPACING);
if (boardPos.x >= tileX && boardPos.x < tileX + TILE_SIZE && boardPos.y >= tileY && boardPos.y < tileY + TILE_SIZE) {
return grid[row][col];
}
}
return null;
}
game.down = function (x, y, obj) {
if (gameOver) return;
var tile = getTileAt(x, y);
if (!tile) return;
pressStartTime = Date.now();
currentPressedTile = tile;
};
game.up = function (x, y, obj) {
if (gameOver || !currentPressedTile) return;
var pressDuration = Date.now() - pressStartTime;
var tile = getTileAt(x, y);
if (tile === currentPressedTile) {
if (pressDuration >= longPressThreshold) {
tile.toggleFlag();
} else {
if (!gameStarted) {
placeMines(tile.row, tile.col);
gameStarted = true;
}
if (!tile.isFlagged) {
revealTile(tile.row, tile.col);
}
}
}
currentPressedTile = null;
};
initializeGrid();
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Minesweeper Classic" and with the description "Classic minesweeper puzzle game with grid-based mine detection, logical deduction gameplay, and immersive sound effects.". No text on banner!
Kırmızı mayın tarlası bayrağı. In-Game asset. 2d. High contrast. No shadows
Kareli bir oyun alanı. In-Game asset. 2d. High contrast. No shadows