User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'y')' in or related to this line: 'playerFleetStatus.y = playerGrid.y + 50;' Line Number: 1630
User prompt
düzelt bir şekilde
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'ships')' in or related to this line: 'for (var i = 0; i < playerGrid.ships.length; i++) {' Line Number: 1674
User prompt
düzelt burayı
User prompt
kolay orta zor seçeneği ekle kolay 8*8 harita orta 16*16 zor 24*24 olsun
User prompt
düşman bir hedef vurursa eğer hedef tamamen yok edilmediyse etrafına saldırmaya devam etsin
User prompt
saldırı haklarını ve kalan hakları 2 taraf içinde solda sayı ile göster
User prompt
karşı oyuncuda saldırı seçeneklerini kullanabilsin. saldırı seçeneklerinden biri kullanılırsa sıra karşıya geçsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
saldırı seçeneklerini oyun alanın solunda göster filoları oyun alanın sağında göster
User prompt
saldırı seçenekleri karşılıklı sırayla kullanılabilsin ardışık saldırı olmaz
User prompt
siha saldırı seçeneği ekle rastgele bir birimi direk vursun batırsın ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
iha saldırı seçeneğini kaldır
User prompt
İHA saldırı seçeneği kesinlikle muhrip yerini işaretlesin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
İHA saldırı seçeneği olsun radarda bir muhrip yerini işaretlesin saldırı yapmasın 1 kez hakkı olsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
iha saldırı seçeneğini kaldır
User prompt
İHA saldırı seçeneği olsun radarda bir kruvazörün yerini işaretlesin saldırı yapmasın 1 kez hakkı olsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
deniz altı saldırısı seçeneği ekle herhangi bir birimi kesin vursun 1 kez hakkı olsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
hava bombardımanı saldırı seçenekleri ekle. hava bombardımanı uçakla rastgele 5 noktaya atış yapsın 1 kez hakkı olsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var GameGrid = Container.expand(function (isPlayerGrid) { var self = Container.call(this); self.isPlayerGrid = isPlayerGrid; self.cells = []; self.ships = []; // Grid size and cell size are now global variables // Initialize grid cells for (var row = 0; row < gridSize; row++) { self.cells[row] = []; for (var col = 0; col < gridSize; col++) { var cell = new GridCell(row, col, isPlayerGrid); cell.x = col * cellSize; cell.y = row * cellSize; self.cells[row][col] = cell; self.addChild(cell); } } // Draw grid lines for (var i = 0; i <= gridSize; i++) { // Vertical lines var vLine = self.attachAsset('gridLine', { width: 2, height: gridSize * cellSize, x: i * cellSize, y: 0 }); // Horizontal lines var hLine = self.attachAsset('gridLine', { width: gridSize * cellSize, height: 2, x: 0, y: i * cellSize }); } self.placeShip = function (startRow, startCol, length, isHorizontal, shipType) { var shipCells = []; // Check if placement is valid for (var i = 0; i < length; i++) { var row = isHorizontal ? startRow : startRow + i; var col = isHorizontal ? startCol + i : startCol; if (row >= gridSize || col >= gridSize || self.cells[row][col].hasShip) { return false; } shipCells.push({ row: row, col: col }); } // Place ship var ship = { cells: shipCells, hits: 0, sunk: false, type: shipType || 'cruiser', length: length, isHorizontal: isHorizontal }; for (var j = 0; j < shipCells.length; j++) { var cellPos = shipCells[j]; self.cells[cellPos.row][cellPos.col].placeShip(ship.type, j, length, isHorizontal); } self.ships.push(ship); return true; }; self.checkHit = function (row, col) { var cell = self.cells[row][col]; if (cell.hasShip) { cell.markHit(); // Find which ship was hit for (var i = 0; i < self.ships.length; i++) { var ship = self.ships[i]; for (var j = 0; j < ship.cells.length; j++) { if (ship.cells[j].row === row && ship.cells[j].col === col) { ship.hits++; if (ship.hits === ship.cells.length && !ship.sunk) { ship.sunk = true; LK.getSound('sunk').play(); // Add fireworks effect for sunk ship self.createFireworks(ship.cells); updateFleetStatus(); return 'sunk'; } return 'hit'; } } } } else { cell.markMiss(); return 'miss'; } }; self.allShipsSunk = function () { for (var i = 0; i < self.ships.length; i++) { if (!self.ships[i].sunk) { return false; } } return true; }; self.createFireworks = function (shipCells) { // Cell size is now a global variable for (var i = 0; i < shipCells.length; i++) { var cellPos = shipCells[i]; var centerX = cellPos.col * cellSize + cellSize / 2; var centerY = cellPos.row * cellSize + cellSize / 2; // Create multiple firework particles for (var f = 0; f < 5; f++) { var firework = self.attachAsset('firework', { anchorX: 0.5, anchorY: 0.5, x: centerX, y: centerY, alpha: 1, scaleX: 0.5, scaleY: 0.5 }); var angle = f / 5 * Math.PI * 2; var distance = 50 + Math.random() * 30; var targetX = centerX + Math.cos(angle) * distance; var targetY = centerY + Math.sin(angle) * distance; tween(firework, { x: targetX, y: targetY, scaleX: 1.2, scaleY: 1.2, alpha: 0 }, { duration: 800 + Math.random() * 400, easing: tween.easeOut, onFinish: function onFinish() { firework.destroy(); } }); } } }; return self; }); var GridCell = Container.expand(function (row, col, isPlayerGrid) { var self = Container.call(this); self.row = row; self.col = col; self.isPlayerGrid = isPlayerGrid; self.hasShip = false; self.isHit = false; self.isMiss = false; // Cell size is now a global variable var waterTile = self.attachAsset('water', { width: cellSize, height: cellSize, x: 0, y: 0, color: 0xffffff }); var shipGraphic = null; var hitMarker = null; var missMarker = null; self.placeShip = function (shipType, segmentIndex, totalLength, isHorizontal) { // Only show ship graphics on player's own grid, hide enemy ships if (!shipGraphic && self.isPlayerGrid) { shipType = shipType || 'cruiser'; // Create main ship hull var hullWidth = isHorizontal ? cellSize - 4 : 20; var hullHeight = isHorizontal ? 20 : cellSize - 4; shipGraphic = self.attachAsset(shipType, { width: hullWidth, height: hullHeight, x: (cellSize - hullWidth) / 2, y: (cellSize - hullHeight) / 2 }); // Add ship details based on type and position if (shipType === 'carrier' || shipType === 'battleship') { // Add deck details var deckWidth = isHorizontal ? hullWidth - 4 : 12; var deckHeight = isHorizontal ? 12 : hullHeight - 4; var deck = self.attachAsset('shipDeck', { width: deckWidth, height: deckHeight, x: (cellSize - deckWidth) / 2, y: (cellSize - deckHeight) / 2 }); // Add turrets for middle segments if (segmentIndex > 0 && segmentIndex < totalLength - 1) { var turret = self.attachAsset('shipTurret', { anchorX: 0.5, anchorY: 0.5, x: cellSize / 2, y: cellSize / 2 }); } } // Add hull reinforcement for bow and stern if (segmentIndex === 0 || segmentIndex === totalLength - 1) { var reinforcement = self.attachAsset('shipHull', { width: isHorizontal ? 8 : 16, height: isHorizontal ? 16 : 8, x: (cellSize - (isHorizontal ? 8 : 16)) / 2, y: (cellSize - (isHorizontal ? 16 : 8)) / 2 }); } } self.hasShip = true; }; self.removeShip = function () { if (shipGraphic) { shipGraphic.destroy(); shipGraphic = null; } self.hasShip = false; }; self.markHit = function () { if (!self.isHit) { hitMarker = self.attachAsset('hit', { anchorX: 0.5, anchorY: 0.5, x: cellSize / 2, y: cellSize / 2 }); self.isHit = true; LK.getSound('hit').play(); LK.getSound('shoot').play(); // Add explosion effect var explosion = self.attachAsset('explosion', { anchorX: 0.5, anchorY: 0.5, x: cellSize / 2, y: cellSize / 2, alpha: 0 }); tween(explosion, { alpha: 1, scaleX: 1.5, scaleY: 1.5 }, { duration: 300, onFinish: function onFinish() { tween(explosion, { alpha: 0 }, { duration: 200, onFinish: function onFinish() { explosion.destroy(); } }); } }); } }; self.markMiss = function () { if (!self.isMiss) { missMarker = self.attachAsset('miss', { anchorX: 0.5, anchorY: 0.5, x: cellSize / 2, y: cellSize / 2 }); self.isMiss = true; LK.getSound('miss').play(); // Add missile effect for miss var missile = self.attachAsset('missile', { anchorX: 0.5, anchorY: 1, x: cellSize / 2, y: -50, alpha: 0.8 }); LK.getSound('shoot').play(); tween(missile, { y: cellSize / 2, alpha: 0.3 }, { duration: 400, onFinish: function onFinish() { missile.destroy(); } }); } }; self.down = function (x, y, obj) { if (gamePhase === 'placement' && self.isPlayerGrid) { handleShipPlacement(self.row, self.col); } else if (gamePhase === 'battle' && !self.isPlayerGrid && !self.isHit && !self.isMiss) { handlePlayerShot(self.row, self.col); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x001122 }); /**** * Game Code ****/ // Game state // Aircraft Carrier - long and wide // Battleship - large // Cruiser - medium // Destroyer - smaller // Submarine - smallest // Hull details // Deck details // Gun turrets var gamePhase = 'difficultySelection'; // 'difficultySelection', 'placement', 'battle', 'gameOver' var selectedDifficulty = null; var gridSize = 8; // Will be set based on difficulty var cellSize = 60; // Will be adjusted based on difficulty var currentShipIndex = 0; var isHorizontal = true; var playerTurn = true; var aiTargets = []; var aiLastHit = null; var aiHuntMode = false; var airBombardmentUsed = false; var airBombardmentInProgress = false; var submarineAttackUsed = false; var submarineAttackInProgress = false; var sihaAttackUsed = false; var sihaAttackInProgress = false; var lastAttackType = null; // Track the last attack type to prevent consecutive use var aiAttackOptions = ['air', 'submarine', 'siha']; // Available AI attack options var aiLastAttackType = null; // Track AI's last attack type var aiAttackCooldowns = { air: false, submarine: false, siha: false }; // Track which AI attacks have been used // Attack rights tracking var playerAttackRights = { air: 2, submarine: 2, siha: 2 }; var aiAttackRights = { air: 2, submarine: 2, siha: 2 }; // Ship sizes to place - realistic naval fleet var shipSizes = [5, 4, 3, 3, 2]; // Carrier, Battleship, Cruiser, Cruiser, Destroyer var shipTypes = ['Uçak Gemisi', 'Savaş Gemisi', 'Kruvazör', 'Kruvazör', 'Muhrip']; var shipAssets = ['carrier', 'battleship', 'cruiser', 'cruiser', 'destroyer']; // Difficulty selection UI var difficultyTitle = new Text2('Zorluk Seviyesi Seçin', { size: 60, fill: 0xFFFFFF }); difficultyTitle.anchor.set(0.5, 0.5); difficultyTitle.x = 1024; difficultyTitle.y = 400; game.addChild(difficultyTitle); var easyButton = new Text2('KOLAY\n8x8 Izgara', { size: 45, fill: 0x00FF00 }); easyButton.anchor.set(0.5, 0.5); easyButton.x = 1024; easyButton.y = 600; game.addChild(easyButton); var mediumButton = new Text2('ORTA\n16x16 Izgara', { size: 45, fill: 0xFFFF00 }); mediumButton.anchor.set(0.5, 0.5); mediumButton.x = 1024; mediumButton.y = 800; game.addChild(mediumButton); var hardButton = new Text2('ZOR\n24x24 Izgara', { size: 45, fill: 0xFF0000 }); hardButton.anchor.set(0.5, 0.5); hardButton.x = 1024; hardButton.y = 1000; game.addChild(hardButton); // Difficulty button handlers easyButton.down = function (x, y, obj) { if (gamePhase === 'difficultySelection') { startGameWithDifficulty('easy'); } }; mediumButton.down = function (x, y, obj) { if (gamePhase === 'difficultySelection') { startGameWithDifficulty('medium'); } }; hardButton.down = function (x, y, obj) { if (gamePhase === 'difficultySelection') { startGameWithDifficulty('hard'); } }; // Grid variables (will be created after difficulty selection) var playerGrid = null; var enemyGrid = null; function startGameWithDifficulty(difficulty) { selectedDifficulty = difficulty; gamePhase = 'placement'; // Set grid size and cell size based on difficulty if (difficulty === 'easy') { gridSize = 8; cellSize = 60; } else if (difficulty === 'medium') { gridSize = 16; cellSize = 30; } else if (difficulty === 'hard') { gridSize = 24; cellSize = 20; } // Hide difficulty selection UI difficultyTitle.visible = false; easyButton.visible = false; mediumButton.visible = false; hardButton.visible = false; // Create grids with selected difficulty playerGrid = new GameGrid(true); enemyGrid = new GameGrid(false); // Calculate appropriate scale based on grid size var maxGridPixelWidth = 720; // Maximum width for grid in pixels var baseGridWidth = gridSize * cellSize; var gridScale = Math.min(1.5, maxGridPixelWidth / baseGridWidth); playerGrid.scaleX = gridScale; playerGrid.scaleY = gridScale; enemyGrid.scaleX = gridScale; enemyGrid.scaleY = gridScale; // Center grids on screen var gridWidth = gridSize * cellSize * gridScale; var screenCenterX = 2048 / 2; var gridCenterX = gridWidth / 2; playerGrid.x = screenCenterX - gridCenterX; playerGrid.y = 1400; enemyGrid.x = screenCenterX - gridCenterX; enemyGrid.y = 400; game.addChild(playerGrid); game.addChild(enemyGrid); // Position grid labels after grids are created enemyLabel.x = enemyGrid.x + gridSize * cellSize * gridScale / 2; enemyLabel.y = enemyGrid.y - 60; playerLabel.x = playerGrid.x + gridSize * cellSize * gridScale / 2; playerLabel.y = playerGrid.y - 60; // Show game UI elements statusText.visible = true; turnText.visible = true; enemyLabel.visible = true; playerLabel.visible = true; rotateButton.visible = true; autoPlaceButton.visible = true; startBattleButton.visible = true; updateStatusText(); } // UI Elements var statusText = new Text2('Gemilerinizi yerleştirin. ' + shipSizes[0] + ' uzunluğunda gemi yerleştirmek için dokunun', { size: 40, fill: 0xFFFFFF }); statusText.anchor.set(0.5, 0); statusText.visible = false; // Hide initially LK.gui.top.addChild(statusText); var turnText = new Text2('', { size: 35, fill: 0xFFFF00 }); turnText.anchor.set(0.5, 0); turnText.y = 80; turnText.visible = false; // Hide initially LK.gui.top.addChild(turnText); // Labels for grids (will be positioned after grid creation) var enemyLabel = new Text2('Düşman Suları', { size: 45, fill: 0xFF6666 }); enemyLabel.anchor.set(0.5, 0.5); enemyLabel.visible = false; // Hide initially game.addChild(enemyLabel); var playerLabel = new Text2('Filonuz', { size: 45, fill: 0x66FF66 }); playerLabel.anchor.set(0.5, 0.5); playerLabel.visible = false; // Hide initially game.addChild(playerLabel); // Rotation button for ship placement var rotateButton = new Text2('Gemiyi Çevir', { size: 40, fill: 0xFFFF00 }); rotateButton.anchor.set(0.5, 0.5); rotateButton.x = 1024; rotateButton.y = 1200; rotateButton.visible = false; // Hide initially game.addChild(rotateButton); rotateButton.down = function (x, y, obj) { if (gamePhase === 'placement') { isHorizontal = !isHorizontal; updateStatusText(); } }; // Auto-placement button var autoPlaceButton = new Text2('Otomatik Yerleştir', { size: 40, fill: 0x00FF00 }); autoPlaceButton.anchor.set(0.5, 0.5); autoPlaceButton.x = 1024; autoPlaceButton.y = 1300; autoPlaceButton.visible = false; // Hide initially game.addChild(autoPlaceButton); autoPlaceButton.down = function (x, y, obj) { if (gamePhase === 'placement') { autoPlacePlayerShips(); } }; // Start battle button var startBattleButton = new Text2('Savaşı Başlat', { size: 40, fill: 0xFF0000 }); startBattleButton.anchor.set(0.5, 0.5); startBattleButton.x = 1024; startBattleButton.y = 1400; startBattleButton.visible = false; // Hide initially game.addChild(startBattleButton); startBattleButton.down = function (x, y, obj) { if (gamePhase === 'placement' && currentShipIndex >= shipSizes.length) { placeAIShips(); gamePhase = 'battle'; rotateButton.visible = false; autoPlaceButton.visible = false; startBattleButton.visible = false; airBombardmentButton.visible = true; submarineAttackButton.visible = true; sihaAttackButton.visible = true; updateStatusText(); } }; // Air bombardment button var airBombardmentButton = new Text2('Hava Bombardımanı', { size: 35, fill: 0xFF6600 }); airBombardmentButton.anchor.set(0, 0.5); airBombardmentButton.x = 50; airBombardmentButton.y = 800; airBombardmentButton.visible = false; game.addChild(airBombardmentButton); airBombardmentButton.down = function (x, y, obj) { if (gamePhase === 'battle' && playerTurn && !airBombardmentUsed && !airBombardmentInProgress && lastAttackType !== 'air') { executeAirBombardment(); } }; // Submarine attack button var submarineAttackButton = new Text2('Denizaltı Saldırısı', { size: 35, fill: 0x0066CC }); submarineAttackButton.anchor.set(0, 0.5); submarineAttackButton.x = 50; submarineAttackButton.y = 900; submarineAttackButton.visible = false; game.addChild(submarineAttackButton); submarineAttackButton.down = function (x, y, obj) { if (gamePhase === 'battle' && playerTurn && !submarineAttackUsed && !submarineAttackInProgress && lastAttackType !== 'submarine') { executeSubmarineAttack(); } }; // SIHA attack button var sihaAttackButton = new Text2('SİHA Saldırısı', { size: 35, fill: 0x9900FF }); sihaAttackButton.anchor.set(0, 0.5); sihaAttackButton.x = 50; sihaAttackButton.y = 1000; sihaAttackButton.visible = false; game.addChild(sihaAttackButton); sihaAttackButton.down = function (x, y, obj) { if (gamePhase === 'battle' && playerTurn && !sihaAttackUsed && !sihaAttackInProgress && lastAttackType !== 'siha') { executeSihaAttack(); } }; // Attack rights display var attackRightsContainer = new Container(); attackRightsContainer.x = 50; attackRightsContainer.y = 1100; game.addChild(attackRightsContainer); var attackRightsTitle = new Text2('Saldırı Hakları', { size: 30, fill: 0xFFFFFF }); attackRightsTitle.anchor.set(0, 0); attackRightsTitle.x = 0; attackRightsTitle.y = 0; attackRightsContainer.addChild(attackRightsTitle); // Player attack rights var playerRightsTitle = new Text2('Oyuncu:', { size: 25, fill: 0x66FF66 }); playerRightsTitle.anchor.set(0, 0); playerRightsTitle.x = 0; playerRightsTitle.y = 40; attackRightsContainer.addChild(playerRightsTitle); var playerAirRightsText = new Text2('Hava: 2', { size: 22, fill: 0xFF6600 }); playerAirRightsText.anchor.set(0, 0); playerAirRightsText.x = 0; playerAirRightsText.y = 70; attackRightsContainer.addChild(playerAirRightsText); var playerSubRightsText = new Text2('Denizaltı: 2', { size: 22, fill: 0x0066CC }); playerSubRightsText.anchor.set(0, 0); playerSubRightsText.x = 0; playerSubRightsText.y = 95; attackRightsContainer.addChild(playerSubRightsText); var playerSihaRightsText = new Text2('SİHA: 2', { size: 22, fill: 0x9900FF }); playerSihaRightsText.anchor.set(0, 0); playerSihaRightsText.x = 0; playerSihaRightsText.y = 120; attackRightsContainer.addChild(playerSihaRightsText); // AI attack rights var aiRightsTitle = new Text2('Düşman:', { size: 25, fill: 0xFF6666 }); aiRightsTitle.anchor.set(0, 0); aiRightsTitle.x = 0; aiRightsTitle.y = 160; attackRightsContainer.addChild(aiRightsTitle); var aiAirRightsText = new Text2('Hava: 2', { size: 22, fill: 0xFF6600 }); aiAirRightsText.anchor.set(0, 0); aiAirRightsText.x = 0; aiAirRightsText.y = 190; attackRightsContainer.addChild(aiAirRightsText); var aiSubRightsText = new Text2('Denizaltı: 2', { size: 22, fill: 0x0066CC }); aiSubRightsText.anchor.set(0, 0); aiSubRightsText.x = 0; aiSubRightsText.y = 215; attackRightsContainer.addChild(aiSubRightsText); var aiSihaRightsText = new Text2('SİHA: 2', { size: 22, fill: 0x9900FF }); aiSihaRightsText.anchor.set(0, 0); aiSihaRightsText.x = 0; aiSihaRightsText.y = 240; attackRightsContainer.addChild(aiSihaRightsText); function updateAttackRightsDisplay() { playerAirRightsText.setText('Hava: ' + playerAttackRights.air); playerSubRightsText.setText('Denizaltı: ' + playerAttackRights.submarine); playerSihaRightsText.setText('SİHA: ' + playerAttackRights.siha); aiAirRightsText.setText('Hava: ' + aiAttackRights.air); aiSubRightsText.setText('Denizaltı: ' + aiAttackRights.submarine); aiSihaRightsText.setText('SİHA: ' + aiAttackRights.siha); // Update button visibility based on available rights if (gamePhase === 'battle') { attackRightsContainer.visible = true; airBombardmentButton.visible = playerAttackRights.air > 0 && lastAttackType !== 'air' && playerTurn; submarineAttackButton.visible = playerAttackRights.submarine > 0 && lastAttackType !== 'submarine' && playerTurn; sihaAttackButton.visible = playerAttackRights.siha > 0 && lastAttackType !== 'siha' && playerTurn; } else { attackRightsContainer.visible = false; } } function updateStatusText() { if (gamePhase === 'placement') { if (currentShipIndex < shipSizes.length) { var orientation = isHorizontal ? 'yatay' : 'dikey'; var shipName = shipTypes[currentShipIndex]; statusText.setText(shipName + ' yerleştirin (' + shipSizes[currentShipIndex] + ' kare, ' + orientation + ')'); } else { statusText.setText('Tüm gemiler yerleştirildi! Savaşı başlatmak için butona tıklayın.'); } } else if (gamePhase === 'battle') { if (playerTurn && !airBombardmentInProgress && !submarineAttackInProgress && !sihaAttackInProgress) { var bombardmentText = playerAttackRights.air > 0 && lastAttackType !== 'air' ? ' | Hava bombardımanı mevcut!' : ''; var submarineText = playerAttackRights.submarine > 0 && lastAttackType !== 'submarine' ? ' | Denizaltı saldırısı mevcut!' : ''; var sihaText = playerAttackRights.siha > 0 && lastAttackType !== 'siha' ? ' | SİHA saldırısı mevcut!' : ''; statusText.setText('Sıra sizde - Düşman ızgarasına ateş edin!' + bombardmentText + submarineText + sihaText); turnText.setText('SİZİN SIRANIZ'); } else if (airBombardmentInProgress) { statusText.setText('Hava bombardımanı devam ediyor...'); turnText.setText('HAVA SALDIRISI'); airBombardmentButton.visible = false; submarineAttackButton.visible = false; sihaAttackButton.visible = false; } else if (submarineAttackInProgress) { statusText.setText('Denizaltı saldırısı devam ediyor...'); turnText.setText('DENİZALTI SALDIRISI'); airBombardmentButton.visible = false; submarineAttackButton.visible = false; sihaAttackButton.visible = false; } else if (sihaAttackInProgress) { statusText.setText('SİHA saldırısı devam ediyor...'); turnText.setText('SİHA SALDIRISI'); airBombardmentButton.visible = false; submarineAttackButton.visible = false; sihaAttackButton.visible = false; } else { var aiHasAttacks = aiAttackRights.air > 0 || aiAttackRights.submarine > 0 || aiAttackRights.siha > 0; var aiAttackText = aiHasAttacks && aiLastAttackType !== 'regular' ? ' (Özel saldırı hazırlanıyor...)' : ''; statusText.setText('Düşman düşünüyor...' + aiAttackText); turnText.setText('DÜŞMAN SIRASI'); } } updateAttackRightsDisplay(); } function handleShipPlacement(row, col) { if (currentShipIndex >= shipSizes.length) return; var shipLength = shipSizes[currentShipIndex]; var shipType = shipAssets[currentShipIndex]; if (playerGrid.placeShip(row, col, shipLength, isHorizontal, shipType)) { currentShipIndex++; updateFleetStatus(); if (currentShipIndex >= shipSizes.length) { // All ships placed, start AI placement placeAIShips(); gamePhase = 'battle'; rotateButton.visible = false; autoPlaceButton.visible = false; updateStatusText(); } else { updateStatusText(); } } } function autoPlacePlayerShips() { // Clear existing ships for (var i = 0; i < playerGrid.ships.length; i++) { var ship = playerGrid.ships[i]; for (var j = 0; j < ship.cells.length; j++) { var cellPos = ship.cells[j]; playerGrid.cells[cellPos.row][cellPos.col].removeShip(); } } playerGrid.ships = []; // Clear all hit and miss markers from the board for (var row = 0; row < gridSize; row++) { for (var col = 0; col < gridSize; col++) { var cell = playerGrid.cells[row][col]; cell.isHit = false; cell.isMiss = false; // Remove any visual markers that might exist if (cell.hitMarker) { cell.hitMarker.destroy(); cell.hitMarker = null; } if (cell.missMarker) { cell.missMarker.destroy(); cell.missMarker = null; } } } // Reset ship placement index currentShipIndex = 0; var playerShipSizes = [5, 4, 3, 3, 2]; var playerShipTypes = ['carrier', 'battleship', 'cruiser', 'cruiser', 'destroyer']; for (var i = 0; i < playerShipSizes.length; i++) { var placed = false; var attempts = 0; while (!placed && attempts < 100) { var row = Math.floor(Math.random() * gridSize); var col = Math.floor(Math.random() * gridSize); var horizontal = Math.random() < 0.5; if (playerGrid.placeShip(row, col, playerShipSizes[i], horizontal, playerShipTypes[i])) { placed = true; currentShipIndex++; } attempts++; } } // Update status text to show current placement state updateStatusText(); updateFleetStatus(); } function placeAIShips() { var aiShipSizes = [5, 4, 3, 3, 2]; var aiShipTypes = ['carrier', 'battleship', 'cruiser', 'cruiser', 'destroyer']; for (var i = 0; i < aiShipSizes.length; i++) { var placed = false; var attempts = 0; while (!placed && attempts < 100) { var row = Math.floor(Math.random() * gridSize); var col = Math.floor(Math.random() * gridSize); var horizontal = Math.random() < 0.5; if (enemyGrid.placeShip(row, col, aiShipSizes[i], horizontal, aiShipTypes[i])) { placed = true; } attempts++; } } } updateFleetStatus(); function handlePlayerShot(row, col) { if (!playerTurn) return; lastAttackType = 'regular'; // Set last attack type for regular shots LK.getSound('shoot').play(); var result = enemyGrid.checkHit(row, col); if (result === 'hit' || result === 'sunk') { LK.setScore(LK.getScore() + (result === 'sunk' ? 100 : 50)); if (enemyGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Zafer! Tüm düşman gemileri yok edildi!'); turnText.setText('KAZANDINIZ!'); LK.showYouWin(); return; } } playerTurn = false; airBombardmentButton.visible = false; submarineAttackButton.visible = false; sihaAttackButton.visible = false; updateStatusText(); // AI turn after delay LK.setTimeout(function () { aiTurn(); }, 1000); } function executeAirBombardment() { if (playerAttackRights.air <= 0 || airBombardmentInProgress) return; playerAttackRights.air--; airBombardmentInProgress = true; lastAttackType = 'air'; // Set last attack type playerTurn = false; updateAttackRightsDisplay(); statusText.setText('Hava bombardımanı başlatıldı! Uçaklar hedefe yaklaşıyor...'); turnText.setText('HAVA SALDIRISI'); // Generate 5 random target positions var targets = []; var attempts = 0; while (targets.length < 5 && attempts < 100) { var row = Math.floor(Math.random() * gridSize); var col = Math.floor(Math.random() * gridSize); var duplicate = false; for (var i = 0; i < targets.length; i++) { if (targets[i].row === row && targets[i].col === col) { duplicate = true; break; } } if (!duplicate) { targets.push({ row: row, col: col }); } attempts++; } // Create aircraft animation var aircraft = game.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5, x: -100, y: 200, scaleX: 2, scaleY: 2, rotation: Math.PI / 4 }); // Animate aircraft flying across screen tween(aircraft, { x: 2148, y: 300 }, { duration: 2000, easing: tween.linear, onFinish: function onFinish() { aircraft.destroy(); // Execute bombardment hits with delays executeTargetHits(targets, 0); } }); } function executeTargetHits(targets, currentIndex) { if (currentIndex >= targets.length) { // All hits completed LK.setTimeout(function () { airBombardmentInProgress = false; if (enemyGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Zafer! Tüm düşman gemileri yok edildi!'); turnText.setText('KAZANDINIZ!'); LK.showYouWin(); return; } // AI turn after air bombardment aiLastAttackType = null; // Reset AI attack type to allow AI special attacks LK.setTimeout(function () { aiTurn(); }, 1000); }, 1000); return; } var target = targets[currentIndex]; // Create bomb falling animation var bomb = game.attachAsset('missile', { anchorX: 0.5, anchorY: 1, x: enemyGrid.x + target.col * cellSize * enemyGrid.scaleX + cellSize * enemyGrid.scaleX / 2, y: 100, alpha: 0.8 }); tween(bomb, { y: enemyGrid.y + target.row * cellSize * enemyGrid.scaleY + cellSize * enemyGrid.scaleY / 2, alpha: 0.3 }, { duration: 600, onFinish: function onFinish() { bomb.destroy(); // Check hit result var result = enemyGrid.checkHit(target.row, target.col); if (result === 'hit' || result === 'sunk') { LK.setScore(LK.getScore() + (result === 'sunk' ? 100 : 50)); } // Continue with next target after short delay LK.setTimeout(function () { executeTargetHits(targets, currentIndex + 1); }, 300); } }); } function executeSubmarineAttack() { if (playerAttackRights.submarine <= 0 || submarineAttackInProgress) return; playerAttackRights.submarine--; submarineAttackInProgress = true; lastAttackType = 'submarine'; // Set last attack type playerTurn = false; updateAttackRightsDisplay(); statusText.setText('Denizaltı saldırısı başlatıldı! Torpido hazırlanıyor...'); turnText.setText('DENİZALTI SALDIRISI'); // Find all enemy ships that are not yet sunk var availableTargets = []; for (var i = 0; i < enemyGrid.ships.length; i++) { var ship = enemyGrid.ships[i]; if (!ship.sunk) { // Add all unhit cells of this ship as potential targets for (var j = 0; j < ship.cells.length; j++) { var cellPos = ship.cells[j]; var cell = enemyGrid.cells[cellPos.row][cellPos.col]; if (!cell.isHit) { availableTargets.push({ row: cellPos.row, col: cellPos.col }); } } } } // If no available targets (all ships sunk or all remaining cells hit), just end if (availableTargets.length === 0) { submarineAttackInProgress = false; playerTurn = true; updateStatusText(); return; } // Select random target from available unhit ship cells var target = availableTargets[Math.floor(Math.random() * availableTargets.length)]; // Create submarine animation from bottom of screen var submarine = game.attachAsset('submarine', { anchorX: 0.5, anchorY: 0.5, x: enemyGrid.x + target.col * cellSize * enemyGrid.scaleX + cellSize * enemyGrid.scaleX / 2, y: 2732 + 100, scaleX: 2, scaleY: 2, alpha: 0.7 }); // Animate submarine rising tween(submarine, { y: enemyGrid.y + target.row * cellSize * enemyGrid.scaleY + 200, alpha: 1 }, { duration: 1500, easing: tween.easeOut, onFinish: function onFinish() { // Create torpedo var torpedo = game.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5, x: submarine.x, y: submarine.y, scaleX: 1.5, scaleY: 1.5, rotation: -Math.PI / 2, alpha: 0.9 }); // Animate torpedo to target tween(torpedo, { x: enemyGrid.x + target.col * cellSize * enemyGrid.scaleX + cellSize * enemyGrid.scaleX / 2, y: enemyGrid.y + target.row * cellSize * enemyGrid.scaleY + cellSize * enemyGrid.scaleY / 2, alpha: 0.5 }, { duration: 800, easing: tween.linear, onFinish: function onFinish() { torpedo.destroy(); // Guaranteed hit on ship var result = enemyGrid.checkHit(target.row, target.col); LK.setScore(LK.getScore() + (result === 'sunk' ? 150 : 75)); // Submarine disappears tween(submarine, { y: 2732 + 100, alpha: 0 }, { duration: 1000, easing: tween.easeIn, onFinish: function onFinish() { submarine.destroy(); submarineAttackInProgress = false; if (enemyGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Zafer! Tüm düşman gemileri yok edildi!'); turnText.setText('KAZANDINIZ!'); LK.showYouWin(); return; } // AI turn after submarine attack aiLastAttackType = null; // Reset AI attack type to allow AI special attacks LK.setTimeout(function () { aiTurn(); }, 1000); } }); } }); } }); } function executeSihaAttack() { if (playerAttackRights.siha <= 0 || sihaAttackInProgress) return; playerAttackRights.siha--; sihaAttackInProgress = true; lastAttackType = 'siha'; // Set last attack type playerTurn = false; updateAttackRightsDisplay(); statusText.setText('SİHA saldırısı başlatıldı! Hedef aranıyor...'); turnText.setText('SİHA SALDIRISI'); // Find all enemy ships that are not yet sunk var availableShips = []; for (var i = 0; i < enemyGrid.ships.length; i++) { var ship = enemyGrid.ships[i]; if (!ship.sunk) { availableShips.push(ship); } } // If no available ships, just end if (availableShips.length === 0) { sihaAttackInProgress = false; playerTurn = true; updateStatusText(); return; } // Select random ship to completely destroy var targetShip = availableShips[Math.floor(Math.random() * availableShips.length)]; var targetCells = []; // Get all cells of the target ship for (var j = 0; j < targetShip.cells.length; j++) { targetCells.push(targetShip.cells[j]); } // Create SIHA drone animation from top of screen var siha = game.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5, x: -100, y: -100, scaleX: 1.8, scaleY: 1.8, rotation: Math.PI / 6, alpha: 0.9 }); // Animate SIHA flying to target area var targetCenterX = enemyGrid.x + targetCells[0].col * 60 * 1.5 + 30 * 1.5; var targetCenterY = enemyGrid.y + targetCells[0].row * 60 * 1.5 + 30 * 1.5; tween(siha, { x: targetCenterX, y: targetCenterY - 150, rotation: 0 }, { duration: 2500, easing: tween.easeInOut, onFinish: function onFinish() { // Hover for targeting tween(siha, { y: targetCenterY - 100, alpha: 1 }, { duration: 800, easing: tween.easeOut, onFinish: function onFinish() { // Execute precision strike - hit all cells of the ship executeShipDestruction(targetCells, 0, siha); } }); } }); } function executeShipDestruction(targetCells, currentIndex, siha) { if (currentIndex >= targetCells.length) { // All cells destroyed, SIHA returns tween(siha, { x: 2200, y: -100, alpha: 0.5 }, { duration: 2000, easing: tween.easeIn, onFinish: function onFinish() { siha.destroy(); sihaAttackInProgress = false; if (enemyGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Zafer! Tüm düşman gemileri yok edildi!'); turnText.setText('KAZANDINIZ!'); LK.showYouWin(); return; } // AI turn after SIHA attack aiLastAttackType = null; // Reset AI attack type to allow AI special attacks LK.setTimeout(function () { aiTurn(); }, 1000); } }); return; } var target = targetCells[currentIndex]; // Create precision missile var missile = game.attachAsset('missile', { anchorX: 0.5, anchorY: 1, x: siha.x, y: siha.y, scaleX: 0.8, scaleY: 0.8, alpha: 0.9 }); tween(missile, { x: enemyGrid.x + target.col * cellSize * enemyGrid.scaleX + cellSize * enemyGrid.scaleX / 2, y: enemyGrid.y + target.row * cellSize * enemyGrid.scaleY + cellSize * enemyGrid.scaleY / 2, alpha: 0.4 }, { duration: 400, easing: tween.linear, onFinish: function onFinish() { missile.destroy(); // Guaranteed hit var result = enemyGrid.checkHit(target.row, target.col); if (result === 'hit' || result === 'sunk') { LK.setScore(LK.getScore() + (result === 'sunk' ? 200 : 100)); } // Continue with next target after short delay LK.setTimeout(function () { executeShipDestruction(targetCells, currentIndex + 1, siha); }, 200); } }); } function executeAIAirBombardment() { aiAttackRights.air--; aiLastAttackType = 'air'; updateAttackRightsDisplay(); statusText.setText('Düşman hava bombardımanı başlattı!'); turnText.setText('DÜŞMAN HAVA SALDIRISI'); // Generate 5 random target positions on player grid var targets = []; var attempts = 0; while (targets.length < 5 && attempts < 100) { var row = Math.floor(Math.random() * gridSize); var col = Math.floor(Math.random() * gridSize); var cell = playerGrid.cells[row][col]; // Only target untouched cells if (!cell.isHit && !cell.isMiss) { var duplicate = false; for (var i = 0; i < targets.length; i++) { if (targets[i].row === row && targets[i].col === col) { duplicate = true; break; } } if (!duplicate) { targets.push({ row: row, col: col }); } } attempts++; } // Create AI aircraft animation var aircraft = game.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5, x: 2148, y: 200, scaleX: 2, scaleY: 2, rotation: -Math.PI * 3 / 4, tint: 0xFF0000 }); // Animate aircraft flying across screen tween(aircraft, { x: -100, y: 300 }, { duration: 2000, easing: tween.linear, onFinish: function onFinish() { aircraft.destroy(); executeAITargetHits(targets, 0); } }); } function executeAITargetHits(targets, currentIndex) { if (currentIndex >= targets.length) { // All hits completed LK.setTimeout(function () { if (playerGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Yenilgi! Filonuz yok edildi!'); turnText.setText('KAYBETTİNİZ!'); LK.showGameOver(); return; } playerTurn = true; lastAttackType = null; updateStatusText(); }, 1000); return; } var target = targets[currentIndex]; // Create bomb falling animation var bomb = game.attachAsset('missile', { anchorX: 0.5, anchorY: 1, x: playerGrid.x + target.col * cellSize * playerGrid.scaleX + cellSize * playerGrid.scaleX / 2, y: 100, alpha: 0.8, tint: 0xFF0000 }); tween(bomb, { y: playerGrid.y + target.row * cellSize * playerGrid.scaleY + cellSize * playerGrid.scaleY / 2, alpha: 0.3 }, { duration: 600, onFinish: function onFinish() { bomb.destroy(); var result = playerGrid.checkHit(target.row, target.col); LK.setTimeout(function () { executeAITargetHits(targets, currentIndex + 1); }, 300); } }); } function executeAISubmarineAttack() { aiAttackRights.submarine--; aiLastAttackType = 'submarine'; updateAttackRightsDisplay(); statusText.setText('Düşman denizaltı saldırısı başlattı!'); turnText.setText('DÜŞMAN DENİZALTI SALDIRISI'); // Find player ships that are not yet sunk var availableTargets = []; for (var i = 0; i < playerGrid.ships.length; i++) { var ship = playerGrid.ships[i]; if (!ship.sunk) { for (var j = 0; j < ship.cells.length; j++) { var cellPos = ship.cells[j]; var cell = playerGrid.cells[cellPos.row][cellPos.col]; if (!cell.isHit) { availableTargets.push({ row: cellPos.row, col: cellPos.col }); } } } } if (availableTargets.length === 0) { playerTurn = true; lastAttackType = null; updateStatusText(); return; } // Select random target from available unhit ship cells var target = availableTargets[Math.floor(Math.random() * availableTargets.length)]; // Create submarine animation var submarine = game.attachAsset('submarine', { anchorX: 0.5, anchorY: 0.5, x: playerGrid.x + target.col * cellSize * playerGrid.scaleX + cellSize * playerGrid.scaleX / 2, y: 2732 + 100, scaleX: 2, scaleY: 2, alpha: 0.7, tint: 0xFF0000 }); // Animate submarine rising tween(submarine, { y: playerGrid.y + target.row * cellSize * playerGrid.scaleY + 200, alpha: 1 }, { duration: 1500, easing: tween.easeOut, onFinish: function onFinish() { // Create torpedo var torpedo = game.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5, x: submarine.x, y: submarine.y, scaleX: 1.5, scaleY: 1.5, rotation: -Math.PI / 2, alpha: 0.9, tint: 0xFF0000 }); // Animate torpedo to target tween(torpedo, { x: playerGrid.x + target.col * cellSize * playerGrid.scaleX + cellSize * playerGrid.scaleX / 2, y: playerGrid.y + target.row * cellSize * playerGrid.scaleY + cellSize * playerGrid.scaleY / 2, alpha: 0.5 }, { duration: 800, easing: tween.linear, onFinish: function onFinish() { torpedo.destroy(); var result = playerGrid.checkHit(target.row, target.col); // Submarine disappears tween(submarine, { y: 2732 + 100, alpha: 0 }, { duration: 1000, easing: tween.easeIn, onFinish: function onFinish() { submarine.destroy(); if (playerGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Yenilgi! Filonuz yok edildi!'); turnText.setText('KAYBETTİNİZ!'); LK.showGameOver(); return; } playerTurn = true; lastAttackType = null; updateStatusText(); } }); } }); } }); } function executeAISihaAttack() { aiAttackRights.siha--; aiLastAttackType = 'siha'; updateAttackRightsDisplay(); statusText.setText('Düşman SİHA saldırısı başlattı!'); turnText.setText('DÜŞMAN SİHA SALDIRISI'); // Find all player ships that are not yet sunk var availableShips = []; for (var i = 0; i < playerGrid.ships.length; i++) { var ship = playerGrid.ships[i]; if (!ship.sunk) { availableShips.push(ship); } } if (availableShips.length === 0) { playerTurn = true; lastAttackType = null; updateStatusText(); return; } // Select random ship to completely destroy var targetShip = availableShips[Math.floor(Math.random() * availableShips.length)]; var targetCells = []; for (var j = 0; j < targetShip.cells.length; j++) { targetCells.push(targetShip.cells[j]); } // Create AI SIHA drone animation var siha = game.attachAsset('missile', { anchorX: 0.5, anchorY: 0.5, x: 2148, y: -100, scaleX: 1.8, scaleY: 1.8, rotation: -Math.PI / 6, alpha: 0.9, tint: 0xFF0000 }); // Animate SIHA flying to target area var targetCenterX = playerGrid.x + targetCells[0].col * cellSize * playerGrid.scaleX + cellSize * playerGrid.scaleX / 2; var targetCenterY = playerGrid.y + targetCells[0].row * cellSize * playerGrid.scaleY + cellSize * playerGrid.scaleY / 2; tween(siha, { x: targetCenterX, y: targetCenterY - 150, rotation: 0 }, { duration: 2500, easing: tween.easeInOut, onFinish: function onFinish() { tween(siha, { y: targetCenterY - 100, alpha: 1 }, { duration: 800, easing: tween.easeOut, onFinish: function onFinish() { executeAIShipDestruction(targetCells, 0, siha); } }); } }); } function executeAIShipDestruction(targetCells, currentIndex, siha) { if (currentIndex >= targetCells.length) { // All cells destroyed, SIHA returns tween(siha, { x: 2200, y: -100, alpha: 0.5 }, { duration: 2000, easing: tween.easeIn, onFinish: function onFinish() { siha.destroy(); if (playerGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Yenilgi! Filonuz yok edildi!'); turnText.setText('KAYBETTİNİZ!'); LK.showGameOver(); return; } playerTurn = true; lastAttackType = null; updateStatusText(); } }); return; } var target = targetCells[currentIndex]; // Create precision missile var missile = game.attachAsset('missile', { anchorX: 0.5, anchorY: 1, x: siha.x, y: siha.y, scaleX: 0.8, scaleY: 0.8, alpha: 0.9, tint: 0xFF0000 }); tween(missile, { x: playerGrid.x + target.col * cellSize * playerGrid.scaleX + cellSize * playerGrid.scaleX / 2, y: playerGrid.y + target.row * cellSize * playerGrid.scaleY + cellSize * playerGrid.scaleY / 2, alpha: 0.4 }, { duration: 400, easing: tween.linear, onFinish: function onFinish() { missile.destroy(); var result = playerGrid.checkHit(target.row, target.col); LK.setTimeout(function () { executeAIShipDestruction(targetCells, currentIndex + 1, siha); }, 200); } }); } function aiTurn() { // Check if AI should use a special attack (30% chance if available and not consecutive) var shouldUseSpecialAttack = Math.random() < 0.3; var availableAttacks = []; // Check which attacks are available (have rights remaining and not the last attack type) if (aiAttackRights.air > 0 && aiLastAttackType !== 'air') { availableAttacks.push('air'); } if (aiAttackRights.submarine > 0 && aiLastAttackType !== 'submarine') { availableAttacks.push('submarine'); } if (aiAttackRights.siha > 0 && aiLastAttackType !== 'siha') { availableAttacks.push('siha'); } // Use special attack if conditions are met if (shouldUseSpecialAttack && availableAttacks.length > 0) { var selectedAttack = availableAttacks[Math.floor(Math.random() * availableAttacks.length)]; if (selectedAttack === 'air') { executeAIAirBombardment(); return; } else if (selectedAttack === 'submarine') { executeAISubmarineAttack(); return; } else if (selectedAttack === 'siha') { executeAISihaAttack(); return; } } // Regular attack logic var row, col; var attempts = 0; if (aiHuntMode && aiLastHit) { // Try adjacent cells to last hit var adjacents = [{ row: aiLastHit.row - 1, col: aiLastHit.col }, { row: aiLastHit.row + 1, col: aiLastHit.col }, { row: aiLastHit.row, col: aiLastHit.col - 1 }, { row: aiLastHit.row, col: aiLastHit.col + 1 }]; var validTargets = []; for (var i = 0; i < adjacents.length; i++) { var target = adjacents[i]; if (target.row >= 0 && target.row < gridSize && target.col >= 0 && target.col < gridSize) { var cell = playerGrid.cells[target.row][target.col]; if (!cell.isHit && !cell.isMiss) { validTargets.push(target); } } } if (validTargets.length > 0) { var chosen = validTargets[Math.floor(Math.random() * validTargets.length)]; row = chosen.row; col = chosen.col; } else { aiHuntMode = false; aiLastHit = null; } } if (!aiHuntMode || aiLastHit && attempts === 0) { // Random targeting do { row = Math.floor(Math.random() * gridSize); col = Math.floor(Math.random() * gridSize); attempts++; } while ((playerGrid.cells[row][col].isHit || playerGrid.cells[row][col].isMiss) && attempts < 100); } var result = playerGrid.checkHit(row, col); if (result === 'hit' || result === 'sunk') { aiLastHit = { row: row, col: col }; aiHuntMode = true; if (result === 'sunk') { aiHuntMode = false; aiLastHit = null; } else if (result === 'hit') { // Ship was hit but not sunk, continue attacking surrounding area LK.setTimeout(function () { aiTurn(); // Continue attacking immediately }, 1500); return; } if (playerGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Yenilgi! Filonuz yok edildi!'); turnText.setText('KAYBETTİNİZ!'); LK.showGameOver(); return; } } playerTurn = true; lastAttackType = null; // Reset attack type after AI turn to allow alternating attacks aiLastAttackType = 'regular'; // Set AI's last attack as regular updateStatusText(); } // Fleet status displays var playerFleetStatus = new Container(); playerFleetStatus.x = 1300; // Initial y position will be set in updateFleetStatus when grids are created game.addChild(playerFleetStatus); var enemyFleetStatus = new Container(); enemyFleetStatus.x = 1300; // Initial y position will be set in updateFleetStatus when grids are created game.addChild(enemyFleetStatus); // Fleet status title texts var playerFleetTitle = new Text2('Filonuz', { size: 35, fill: 0x66FF66 }); playerFleetTitle.anchor.set(0.5, 0); playerFleetTitle.x = 0; playerFleetTitle.y = -40; playerFleetStatus.addChild(playerFleetTitle); var enemyFleetTitle = new Text2('Düşman Filosu', { size: 35, fill: 0xFF6666 }); enemyFleetTitle.anchor.set(0.5, 0); enemyFleetTitle.x = 0; enemyFleetTitle.y = -40; enemyFleetStatus.addChild(enemyFleetTitle); // Fleet status arrays var playerFleetDisplay = []; var enemyFleetDisplay = []; function updateFleetStatus() { // Return early if grids haven't been created yet if (!playerGrid || !enemyGrid) { return; } // Return early if grids don't have ships arrays or position properties if (!playerGrid.ships || !enemyGrid.ships || playerGrid.y === undefined || playerGrid.y === null || enemyGrid.y === undefined || enemyGrid.y === null) { return; } // Update fleet status container positions only if grids exist and have valid coordinates if (playerGrid && playerFleetStatus && playerGrid.y !== undefined && playerGrid.y !== null) { playerFleetStatus.y = playerGrid.y + 50; } if (enemyGrid && enemyFleetStatus && enemyGrid.y !== undefined && enemyGrid.y !== null) { enemyFleetStatus.y = enemyGrid.y + 50; } // Initialize arrays if they don't exist if (!playerFleetDisplay) playerFleetDisplay = []; if (!enemyFleetDisplay) enemyFleetDisplay = []; // Clear existing displays for (var i = 0; i < playerFleetDisplay.length; i++) { playerFleetDisplay[i].destroy(); } for (var i = 0; i < enemyFleetDisplay.length; i++) { enemyFleetDisplay[i].destroy(); } playerFleetDisplay = []; enemyFleetDisplay = []; // Update player fleet status for (var i = 0; i < playerGrid.ships.length; i++) { var ship = playerGrid.ships[i]; // Create ship container for better organization var shipContainer = new Container(); shipContainer.x = 0; shipContainer.y = i * 60; playerFleetStatus.addChild(shipContainer); playerFleetDisplay.push(shipContainer); // Ship name and status var healthPercent = Math.round((ship.length - ship.hits) / ship.length * 100); var statusText = new Text2(shipTypes[i], { size: 32, fill: ship.sunk ? 0xFF4444 : 0x66FF99 }); statusText.anchor.set(0, 0); statusText.x = 0; statusText.y = 0; shipContainer.addChild(statusText); // Health bar background var healthBg = LK.getAsset('water', { width: 120, height: 8, x: 0, y: 25, color: 0x333333 }); shipContainer.addChild(healthBg); // Health bar fill var healthWidth = Math.max(0, 120 * (ship.length - ship.hits) / ship.length); var healthBar = LK.getAsset('water', { width: healthWidth, height: 8, x: 0, y: 25, color: ship.sunk ? 0xFF0000 : healthPercent > 60 ? 0x00FF00 : healthPercent > 30 ? 0xFFFF00 : 0xFF6600 }); shipContainer.addChild(healthBar); // Health text var healthText = new Text2(ship.hits + '/' + ship.length + ' İsabet', { size: 20, fill: 0xCCCCCC }); healthText.anchor.set(0, 0); healthText.x = 0; healthText.y = 35; shipContainer.addChild(healthText); // Ship icon with segments for (var seg = 0; seg < ship.length; seg++) { var segmentColor = 0x888888; var segmentAlpha = 0.8; // Check if this segment is hit var segmentHit = false; for (var cellIdx = 0; cellIdx < ship.cells.length; cellIdx++) { if (cellIdx === seg) { var cell = playerGrid.cells[ship.cells[cellIdx].row][ship.cells[cellIdx].col]; if (cell.isHit) { segmentHit = true; break; } } } if (segmentHit) { segmentColor = 0xFF0000; segmentAlpha = 1.0; } else if (ship.sunk) { segmentColor = 0x444444; segmentAlpha = 0.5; } var segment = LK.getAsset('water', { width: 18, height: 12, x: 130 + seg * 20, y: 8, color: segmentColor }); segment.alpha = segmentAlpha; shipContainer.addChild(segment); } } // Update enemy fleet status for (var i = 0; i < enemyGrid.ships.length; i++) { var ship = enemyGrid.ships[i]; // Create ship container for better organization var shipContainer = new Container(); shipContainer.x = 0; shipContainer.y = i * 60; enemyFleetStatus.addChild(shipContainer); enemyFleetDisplay.push(shipContainer); // Ship name and status (only show if sunk or hit) var statusColor = 0xCCCCCC; var statusText = shipTypes[i]; if (ship.sunk) { statusColor = 0xFF4444; statusText += ' - BATIK'; } else if (ship.hits > 0) { statusColor = 0xFFAA00; statusText += ' - Hasarlı'; } else { statusText += ' - Bilinmiyor'; } var nameText = new Text2(statusText, { size: 32, fill: statusColor }); nameText.anchor.set(0, 0); nameText.x = 0; nameText.y = 0; shipContainer.addChild(nameText); // Only show detailed info if ship has been hit if (ship.hits > 0 || ship.sunk) { // Health bar background var healthBg = LK.getAsset('water', { width: 120, height: 8, x: 0, y: 25, color: 0x333333 }); shipContainer.addChild(healthBg); // Health bar fill var healthWidth = Math.max(0, 120 * (ship.length - ship.hits) / ship.length); var healthBar = LK.getAsset('water', { width: healthWidth, height: 8, x: 0, y: 25, color: ship.sunk ? 0xFF0000 : 0xFFAA00 }); shipContainer.addChild(healthBar); // Health text var healthText = new Text2(ship.hits + '/' + ship.length + ' İsabet', { size: 20, fill: 0xCCCCCC }); healthText.anchor.set(0, 0); healthText.x = 0; healthText.y = 35; shipContainer.addChild(healthText); // Ship segments (only show hits) for (var seg = 0; seg < ship.length; seg++) { var segmentColor = 0x555555; var segmentAlpha = 0.3; // Check if this segment is hit var segmentHit = false; for (var cellIdx = 0; cellIdx < ship.cells.length; cellIdx++) { if (cellIdx === seg) { var cell = enemyGrid.cells[ship.cells[cellIdx].row][ship.cells[cellIdx].col]; if (cell.isHit) { segmentHit = true; segmentColor = 0xFF0000; segmentAlpha = 1.0; break; } } } var segment = LK.getAsset('water', { width: 18, height: 12, x: 130 + seg * 20, y: 8, color: segmentColor }); segment.alpha = segmentAlpha; shipContainer.addChild(segment); } } else { // Show question marks for unknown ships var unknownText = new Text2('? ? ? ? ?', { size: 24, fill: 0x666666 }); unknownText.anchor.set(0, 0); unknownText.x = 130; unknownText.y = 15; shipContainer.addChild(unknownText); } } } // Initial setup updateStatusText(); updateAttackRightsDisplay(); game.update = function () { // Game loop updates };
===================================================================
--- original.js
+++ change.js
@@ -1593,13 +1593,13 @@
}
// Fleet status displays
var playerFleetStatus = new Container();
playerFleetStatus.x = 1300;
-playerFleetStatus.y = playerGrid.y + 50;
+// Initial y position will be set in updateFleetStatus when grids are created
game.addChild(playerFleetStatus);
var enemyFleetStatus = new Container();
enemyFleetStatus.x = 1300;
-enemyFleetStatus.y = enemyGrid.y + 50;
+// Initial y position will be set in updateFleetStatus when grids are created
game.addChild(enemyFleetStatus);
// Fleet status title texts
var playerFleetTitle = new Text2('Filonuz', {
size: 35,
sketch tarzında carrier gemisi. In-Game asset. 2d. High contrast. No shadows
sketch tarzında cruıser savas gemısı. In-Game asset. 2d. High contrast. No shadows
skecth tarzında destroyer savas gemisi. In-Game asset. 2d. High contrast. No shadows
suya düşen füze. In-Game asset. 2d. High contrast. No shadows
suya düşen nesne sonrası oluşan dalgacıklar. In-Game asset. 2d. High contrast. No shadows
patlama sonrası kıvılcımlar. In-Game asset. 2d. High contrast. No shadows
aşağı yönde giden füze. In-Game asset. 2d. High contrast. No shadows
denizaltı gemisi torpidosundan ateşleme. In-Game asset. 2d. High contrast. No shadows