Code edit (2 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
skor artmıyor onu düzelt
User prompt
Please fix the bug: 'Uncaught ReferenceError: scoreTxt is not defined' in or related to this line: 'scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start.' Line Number: 137
User prompt
Please fix the bug: 'Uncaught ReferenceError: scoreTxt is not defined' in or related to this line: 'scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start.' Line Number: 137
User prompt
Please fix the bug: 'Uncaught ReferenceError: scoreTxt is not defined' in or related to this line: 'scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start.' Line Number: 51
User prompt
oyuna score ekleyelim her emerald bulduğumuzda score artsın
User prompt
kaybetdiğimde bombsound sesi çalsın
User prompt
oyun bitdiğinde bombsound asseti çalışmıyor onu düzelt
User prompt
oyun bitdiğinde bombsound asseti eklensin
User prompt
bomba karesine tıklandığında bombsound asseti eklensin
User prompt
emerald karesine tıkladığımız zaman emeraldsound asseti eklensin
User prompt
emerald karesini açtığımızda ses gelsin ona uygun
User prompt
Game Over yerine Kaybetdiniz! yazılsın
User prompt
kaybetme ekranında Game Over yerine Kaybetdiniz! yazılsın
User prompt
bombaya tıkladığımızda ekrana kaybetme animasyonu ekle ekran karalsın ve erkana game over menüsü gelsin
User prompt
yukarıdakı kırmızı ve yeşil mesajları kaldır
User prompt
eğer tıkladığımız kare yeşilse ora emerald asseti ekle eğer kırmızıysa ora bomb asseti ekle
/**** * Classes ****/ // Kliklenebilen kvadrat sinfi yarat var ClickableSquare = Container.expand(function () { var self = Container.call(this); // Kvadrat üçün görünüsh təyin edir var squareGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.graphics = squareGraphics; // Kliklenən zaman davranış self.down = function (x, y, obj) { if (self.type === 'bomb') { self.graphics.tint = 0xff0000; // Red // Add bomb asset to the clicked square var bombAsset = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5 }); // Play a sound LK.getSound('bombsound').play(); // Game over - loss endGame(false); // Add game over animation LK.effects.flashScreen(0xff0000, 1000); // Show game over menu LK.showGameOver(); } else if (self.type === 'emerald' && !self.clicked) { // Check if emerald has already been clicked self.graphics.tint = 0x00ff00; // Green incrementScore(); // Increase score checkWin(); // Check for win // Add emerald asset to the clicked square var emeraldAsset = self.attachAsset('emerald', { anchorX: 0.5, anchorY: 0.5 }); // Mark this emerald as clicked self.clicked = true; // Set a clicked flag // Play a sound LK.getSound('emeraldSound').play(); // Update and display the score in the game. scoreTxt.setText(score); // Corrected the reference to 'score' } }; }); /**** * Initialize Game ****/ /**** * Oyun deyişenləri ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Shəbəkəni qur var showMessage = function showMessage(message, color) { var messageBox = new Text2(message, { size: 64, fill: color || "#ffffff", align: "center", wordWrap: true, wordWrapWidth: 500 }); messageBox.x = 1024; // X koordinat (merkəzdə olsun) messageBox.y = 100; // Y koordinat yuxari mərkəzdə messageBox.anchorX = 0.5; messageBox.anchorY = 0.5; game.addChild(messageBox); // Mesajın dərhal silinməsi üçün kiçik gecikmə LK.setTimeout(function () { return game.removeChild(messageBox); }, 2000); // 2 saniyədən sonra mesajın silinməsi }; /**** * Oyun deyişenləri ****/ var grid = []; var gridSize = 5; // 5x5 shebeke var cellSpacing = 10; // Xanalar arasi boshluq 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 xali var totalEmeralds = emeraldCount; /**** * Məntiqi Funksiyalar ****/ function placeObjects() { var availableCells = []; // Movcud butun xanalardan siyahi yaradırıq for (var i = 0; i < gridSize; i++) { for (var j = 0; j < gridSize; j++) { availableCells.push({ x: i, y: j }); } } // Minalari tesadufi yerleştir 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 yerleştir } // Zumrudleri tesadufi yerleştir 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 yerleştir } } // Define scoreTxt var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Oyunçunun xalini artir function incrementScore() { score++; // Increment the score // Update and display the score in the game. scoreTxt.setText(score); // Make sure 'score' is used directly here } // Oyunu bitir function endGame(win) { if (win) { console.log("Tebrikler! Siz qalibsiniz!"); showMessage("Tebrikler! Qazandiniz!", "#00ff00"); } else { console.log("Bomba partladi! Oyun bitdi."); showMessage("Kaybettiniz!", "#ff0000"); // Add game over animation LK.effects.flashScreen(0xff0000, 1000); // Play a sound LK.getSound('bombsound').play(); // Show game over menu with custom text LK.showGameOver({ text: "Kaybettiniz!" }); } // Restart üçün əlavə məntiq yazabilirsiniz } // Qalibiyyeti yoxla function checkWin() { if (score === totalEmeralds) { endGame(true); } } // Grid daxilində kvadratları yaratmaq 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 yerleştir placeObjects();
===================================================================
--- original.js
+++ change.js
@@ -26,21 +26,24 @@
// Add game over animation
LK.effects.flashScreen(0xff0000, 1000);
// Show game over menu
LK.showGameOver();
- } else if (self.type === 'emerald') {
+ } else if (self.type === 'emerald' && !self.clicked) {
+ // Check if emerald has already been clicked
self.graphics.tint = 0x00ff00; // Green
incrementScore(); // Increase score
checkWin(); // Check for win
// Add emerald asset to the clicked square
var emeraldAsset = self.attachAsset('emerald', {
anchorX: 0.5,
anchorY: 0.5
});
+ // Mark this emerald as clicked
+ self.clicked = true; // Set a clicked flag
// Play a sound
LK.getSound('emeraldSound').play();
// Update and display the score in the game.
- scoreTxt.setText(LK.getScore()); // LK.getScore is initialized to zero at game start.
+ scoreTxt.setText(score); // Corrected the reference to 'score'
}
};
});
@@ -124,11 +127,11 @@
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Oyunçunun xalini artir
function incrementScore() {
- score++;
+ score++; // Increment the score
// Update and display the score in the game.
- scoreTxt.setText(score);
+ scoreTxt.setText(score); // Make sure 'score' is used directly here
}
// Oyunu bitir
function endGame(win) {
if (win) {
@@ -166,6 +169,6 @@
game.addChild(cell);
grid[i][j] = cell;
}
}
-// Obyektleri yerleştir
+// Obyektləri yerleştir
placeObjects();
\ No newline at end of file