Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 46
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 46
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'thisObject.type = 'menu';' Line Number: 47
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'thisObject.type = 'menu';' Line Number: 47
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'thisObject.type = 'menu';' Line Number: 47
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'thisObject.type = 'menu';' Line Number: 47
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'thisObject.type = 'menu';' Line Number: 47
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'thisObject.type = 'menu';' Line Number: 47
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'type')' in or related to this line: 'self.type = 'menu';' Line Number: 45
/****
* Classes
****/
// Kliklenebilen kvadrat sinfi yarat
var ClickableSquare = Container.expand(function () {
var self = Container.call(this);
self.type = 'menu'; // Define 'type' property
var squareGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphics = squareGraphics;
self.down = function (x, y, obj) {
if (self.type === 'bomb') {
self.graphics = self.attachAsset('mine', {
anchorX: 0.5,
anchorY: 0.5
});
console.log("Bomba partladi! Oyun bitdi.");
endGame(false); // Oyun bitdi - məğlubiyyət
} else if (self.type === 'emerald') {
self.graphics = self.attachAsset('emerald', {
anchorX: 0.5,
anchorY: 0.5
});
console.log("Zumrud tapdınız!");
incrementScore(); // Xalı artır
checkWin(); // Qalibiyyəti yoxla
} else if (self.type === 'menu') {
gridSize = self.value; // Set grid size
startGame(); // Start the game
}
};
});
// Menu item class
var MenuItem = ClickableSquare.expand(function () {
var self = ClickableSquare.call(this);
self.type = 'menu';
return self;
});
/****
* Initialize Game
****/
/****
* Oyun dəyişənləri
****/
/****
* Oyun Tərtibatı
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Şəbəkəni qur
/****
* Oyun dəyişənləri
****/
var grid = [];
var gridSize = 5; // 5x5 şəbəkə
var cellSpacing = 10; // Xanalar arası boşluq
var cellSize = (Math.min(2048, 2732) - (gridSize - 1) * cellSpacing) / gridSize;
var gridStartX = (2048 - gridSize * cellSize - (gridSize - 1) * cellSpacing) / 2;
var gridStartY = (2732 - gridSize * cellSize - (gridSize - 1) * cellSpacing) / 2;
var bombCount = 2; // 2 mina
var emeraldCount = 23; // 23 zumrud
var score = 0; // Oyunçunun xalı
var totalEmeralds = emeraldCount;
/****
* Məntiqi Funksiyalar
****/
// Minaları və zumrudları təsadüfi yerləşdir
function placeObjects() {
var availableCells = [];
// Mövcud bütün xanalar üçün siyahı yaradırıq
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
availableCells.push({
x: i,
y: j
});
}
}
// Minaları təsadüfi yerləşdir
for (var b = 0; b < bombCount; b++) {
var randomIndex = Math.floor(Math.random() * availableCells.length);
var cellPos = availableCells.splice(randomIndex, 1)[0];
grid[cellPos.x][cellPos.y].type = 'bomb'; // Mina yerləşdir
}
// Zumrudları təsadüfi yerləşdir
for (var e = 0; e < emeraldCount; e++) {
var randomIndex = Math.floor(Math.random() * availableCells.length);
var cellPos = availableCells.splice(randomIndex, 1)[0];
grid[cellPos.x][cellPos.y].type = 'emerald'; // Zumrud yerləşdir
}
}
// Oyunçunun xalı artır
function incrementScore() {
score++;
}
// Oyunu bitir
function endGame(win) {
if (win) {
console.log("Təbriklər! Siz qalibsiniz!");
showMessage("Təbriklər! Qalibsiniz!", 0x00FF00); // Qələbə mesajı
} else {
console.log("Bomba partladı! Oyun bitdi.");
showMessage("Bomba partladı! Oyun bitdi!", 0xFF0000); // Məğlubiyyət mesajı
}
// Ekranda bir flash effekti əlavə et
LK.effects.flashScreen(0x000000, 1000);
// Oyunu bitir və sona qədər ekranı göstər
LK.showGameOver();
}
// Qalibiyyəti yoxla
function checkWin() {
if (score === totalEmeralds) {
endGame(true);
}
}
// Oyun başladı
function startGame() {
grid = []; // Clear the grid array before starting the game
// Şəbəkəni qur
for (var i = 0; i < gridSize; i++) {
grid[i] = [];
for (var j = 0; j < gridSize; j++) {
var cell = new ClickableSquare();
cell.x = gridStartX + j * (cellSize + cellSpacing) + cellSize / 2;
cell.y = gridStartY + i * (cellSize + cellSpacing) + cellSize / 2;
cell.width = cellSize;
cell.height = cellSize;
game.addChild(cell);
grid[i][j] = cell;
}
}
// Obyektləri yerləşdir
placeObjects();
}
// Ekranda mesaj göstərmək üçün əlavə funksiya
function showMessage(message, color) {
var msg = new LK.Text({
text: message,
color: color,
fontSize: 40,
textAlign: 'center',
anchorX: 0.5,
anchorY: 0.5
});
msg.x = 2048 / 2;
msg.y = 2732 / 2;
game.addChild(msg);
// Mesajı 3 saniyə sonra sil
setTimeout(function () {
game.removeChild(msg);
}, 3000);
}
// Menyu yaradılması (oyun başlamazdan əvvəl)
var menuItems = [3, 4, 5];
for (var i = 0; i < menuItems.length; i++) {
var menuItem = new MenuItem();
menuItem.value = menuItems[i];
menuItem.x = 2048 / 2;
menuItem.y = 2732 / menuItems.length * i + cellSize / 2;
menuItem.width = cellSize;
menuItem.height = cellSize;
game.addChild(menuItem);
} /****
* Classes
****/
// Kliklenebilen kvadrat sinfi yarat
var ClickableSquare = Container.expand(function () {
var self = Container.call(this);
self.type = 'menu'; // Define 'type' property
var squareGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphics = squareGraphics;
self.down = function (x, y, obj) {
if (self.type === 'bomb') {
self.graphics = self.attachAsset('mine', {
anchorX: 0.5,
anchorY: 0.5
});
console.log("Bomba partladi! Oyun bitdi.");
endGame(false); // Oyun bitdi - məğlubiyyət
} else if (self.type === 'emerald') {
self.graphics = self.attachAsset('emerald', {
anchorX: 0.5,
anchorY: 0.5
});
console.log("Zumrud tapdınız!");
incrementScore(); // Xalı artır
checkWin(); // Qalibiyyəti yoxla
} else if (self.type === 'menu') {
gridSize = self.value; // Set grid size
startGame(); // Start the game
}
};
});
// Menu item class
var MenuItem = ClickableSquare.expand(function () {
var self = ClickableSquare.call(this);
self.type = 'menu';
return self;
});
/****
* Initialize Game
****/
/****
* Oyun dəyişənləri
****/
/****
* Oyun Tərtibatı
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Şəbəkəni qur
/****
* Oyun dəyişənləri
****/
var grid = [];
var gridSize = 5; // 5x5 şəbəkə
var cellSpacing = 10; // Xanalar arası boşluq
var cellSize = (Math.min(2048, 2732) - (gridSize - 1) * cellSpacing) / gridSize;
var gridStartX = (2048 - gridSize * cellSize - (gridSize - 1) * cellSpacing) / 2;
var gridStartY = (2732 - gridSize * cellSize - (gridSize - 1) * cellSpacing) / 2;
var bombCount = 2; // 2 mina
var emeraldCount = 23; // 23 zumrud
var score = 0; // Oyunçunun xalı
var totalEmeralds = emeraldCount;
/****
* Məntiqi Funksiyalar
****/
// Minaları və zumrudları təsadüfi yerləşdir
function placeObjects() {
var availableCells = [];
// Mövcud bütün xanalar üçün siyahı yaradırıq
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
availableCells.push({
x: i,
y: j
});
}
}
// Minaları təsadüfi yerləşdir
for (var b = 0; b < bombCount; b++) {
var randomIndex = Math.floor(Math.random() * availableCells.length);
var cellPos = availableCells.splice(randomIndex, 1)[0];
grid[cellPos.x][cellPos.y].type = 'bomb'; // Mina yerləşdir
}
// Zumrudları təsadüfi yerləşdir
for (var e = 0; e < emeraldCount; e++) {
var randomIndex = Math.floor(Math.random() * availableCells.length);
var cellPos = availableCells.splice(randomIndex, 1)[0];
grid[cellPos.x][cellPos.y].type = 'emerald'; // Zumrud yerləşdir
}
}
// Oyunçunun xalı artır
function incrementScore() {
score++;
}
// Oyunu bitir
function endGame(win) {
if (win) {
console.log("Təbriklər! Siz qalibsiniz!");
showMessage("Təbriklər! Qalibsiniz!", 0x00FF00); // Qələbə mesajı
} else {
console.log("Bomba partladı! Oyun bitdi.");
showMessage("Bomba partladı! Oyun bitdi!", 0xFF0000); // Məğlubiyyət mesajı
}
// Ekranda bir flash effekti əlavə et
LK.effects.flashScreen(0x000000, 1000);
// Oyunu bitir və sona qədər ekranı göstər
LK.showGameOver();
}
// Qalibiyyəti yoxla
function checkWin() {
if (score === totalEmeralds) {
endGame(true);
}
}
// Oyun başladı
function startGame() {
grid = []; // Clear the grid array before starting the game
// Şəbəkəni qur
for (var i = 0; i < gridSize; i++) {
grid[i] = [];
for (var j = 0; j < gridSize; j++) {
var cell = new ClickableSquare();
cell.x = gridStartX + j * (cellSize + cellSpacing) + cellSize / 2;
cell.y = gridStartY + i * (cellSize + cellSpacing) + cellSize / 2;
cell.width = cellSize;
cell.height = cellSize;
game.addChild(cell);
grid[i][j] = cell;
}
}
// Obyektləri yerləşdir
placeObjects();
}
// Ekranda mesaj göstərmək üçün əlavə funksiya
function showMessage(message, color) {
var msg = new LK.Text({
text: message,
color: color,
fontSize: 40,
textAlign: 'center',
anchorX: 0.5,
anchorY: 0.5
});
msg.x = 2048 / 2;
msg.y = 2732 / 2;
game.addChild(msg);
// Mesajı 3 saniyə sonra sil
setTimeout(function () {
game.removeChild(msg);
}, 3000);
}
// Menyu yaradılması (oyun başlamazdan əvvəl)
var menuItems = [3, 4, 5];
for (var i = 0; i < menuItems.length; i++) {
var menuItem = new MenuItem();
menuItem.value = menuItems[i];
menuItem.x = 2048 / 2;
menuItem.y = 2732 / menuItems.length * i + cellSize / 2;
menuItem.width = cellSize;
menuItem.height = cellSize;
game.addChild(menuItem);
}