User prompt
oyunu yeniden başlat butonunu kaldır
User prompt
oyunu yeniden başlat butonu ekle
User prompt
Gemilerin yerleşim gösterimini iyileştir
User prompt
yerleşim alanı a4 kareli kağıt gibi olsun beyaz üstü mavi çizgili
User prompt
oyun alanını biraz yakınlaştır ve ortala
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < playerFleetDisplay.length; i++) {' Line Number: 667
User prompt
herkesin filosunu tahtanın yanında anlık göster. komple battığında onu yandaki listede de göster
User prompt
her yerleştirmeye basıldığında tahtayı sıfırla izler bırakma
User prompt
otomatik yerleşim sınırsız yapabileyim
User prompt
otomatik yerleşim yapacak buton ekle
User prompt
füze sesleri ekle
User prompt
rakibin yerleşimini oyuncuya gizle
User prompt
gerçek gemi modelleri kullan
User prompt
1. *Oyun Alanı*: - Birbirine bakan 10x10 karelerden oluşan bir ızgara - Yatay eksen *harfler A-J, dikey eksen **sayılar 1-10* ile etiketlenmiştir (örneğin: A1, B5, J10). 2. *Gemileri Yerleştirme*: - Oyuncular gemilerini ızgaraya *gizlice* yerleştirir. Klasik gemiler ve boyutları: - *1 Amiral (4 kare)* - *2 Kruvazör (3 kare)* - *3 Muhrip (2 kare)* - *4 Denizaltı (1 kare)* - Gemiler *yatay veya dikey* olarak yerleştirilir, çapraz veya üst üste olamazlar. 3. *Oyun Akışı*: - Oyuncular sırayla bir *koordinat* (örneğin: "C7") seçip ateş ederler. - Rakip, o karede bir gemi olup olmadığını seçecektir. - *"Iska"* - *Verilen hasar* - *Batırılan* seçenekler 4. *Kazanma Koşulu*: - Tüm gemileri batıran ilk oyuncu kazanır! yapay zekaya karşı oyna Seçilen koordinata bir atış yapıldığında, ıskalar o koordinatta suya düşen patlamamış bir füze olarak görünecektir. Hasar verilirse, o koordinatta bir patlama olacaktır. Tamamen batarsa havai fişekler olacak. Top ateşi sesleri de olacak ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Battleship Commander
Initial prompt
amiral battı oyunu
/**** * 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 = []; var gridSize = 8; var cellSize = 60; // 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) { var cellSize = 60; 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; var cellSize = 60; 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 ****/ // Gun turrets // Deck details // Hull details // Submarine - smallest // Destroyer - smaller // Cruiser - medium // Battleship - large // Aircraft Carrier - long and wide // Game state var gamePhase = 'placement'; // 'placement', 'battle', 'gameOver' var currentShipIndex = 0; var isHorizontal = true; var playerTurn = true; var aiTargets = []; var aiLastHit = null; var aiHuntMode = false; // 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']; // Create grids var playerGrid = new GameGrid(true); var enemyGrid = new GameGrid(false); // Scale up grids for better visibility playerGrid.scaleX = 1.5; playerGrid.scaleY = 1.5; enemyGrid.scaleX = 1.5; enemyGrid.scaleY = 1.5; // Center grids on screen var gridWidth = 8 * 60 * 1.5; // 8 cells * 60px * scale 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); // 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); LK.gui.top.addChild(statusText); var turnText = new Text2('', { size: 35, fill: 0xFFFF00 }); turnText.anchor.set(0.5, 0); turnText.y = 80; LK.gui.top.addChild(turnText); // Labels for grids var enemyLabel = new Text2('Düşman Suları', { size: 45, fill: 0xFF6666 }); enemyLabel.anchor.set(0.5, 0.5); enemyLabel.x = enemyGrid.x + 8 * 60 * 1.5 / 2; enemyLabel.y = enemyGrid.y - 60; game.addChild(enemyLabel); var playerLabel = new Text2('Filonuz', { size: 45, fill: 0x66FF66 }); playerLabel.anchor.set(0.5, 0.5); playerLabel.x = playerGrid.x + 8 * 60 * 1.5 / 2; playerLabel.y = playerGrid.y - 60; 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; 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; 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; 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; updateStatusText(); } }; 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) { statusText.setText('Sıra sizde - Düşman ızgarasına ateş edin!'); turnText.setText('SİZİN SIRANIZ'); } else { statusText.setText('Düşman düşünüyor...'); turnText.setText('DÜŞMAN SIRASI'); } } } 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 < 8; row++) { for (var col = 0; col < 8; 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() * 8); var col = Math.floor(Math.random() * 8); 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() * 8); var col = Math.floor(Math.random() * 8); 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; 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; updateStatusText(); // AI turn after delay LK.setTimeout(function () { aiTurn(); }, 1000); } function aiTurn() { 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 < 8 && target.col >= 0 && target.col < 8) { 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() * 8); col = Math.floor(Math.random() * 8); 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; } if (playerGrid.allShipsSunk()) { gamePhase = 'gameOver'; statusText.setText('Yenilgi! Filonuz yok edildi!'); turnText.setText('KAYBETTİNİZ!'); LK.showGameOver(); return; } } playerTurn = true; updateStatusText(); } // Fleet status displays var playerFleetStatus = new Container(); playerFleetStatus.x = playerGrid.x + 8 * 60 * 1.5 + 50; playerFleetStatus.y = playerGrid.y; game.addChild(playerFleetStatus); var enemyFleetStatus = new Container(); enemyFleetStatus.x = enemyGrid.x + 8 * 60 * 1.5 + 50; enemyFleetStatus.y = enemyGrid.y; 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() { // 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]; var statusText = new Text2(shipTypes[i] + ' (' + ship.length + ')', { size: 28, fill: ship.sunk ? 0xFF0000 : 0x66FF66 }); statusText.anchor.set(0, 0); statusText.x = -100; statusText.y = i * 35; playerFleetStatus.addChild(statusText); playerFleetDisplay.push(statusText); // Add ship icon var shipIcon = LK.getAsset(ship.type, { width: 30, height: 8, anchorX: 0, anchorY: 0, x: 120, y: i * 35 + 5 }); if (ship.sunk) { shipIcon.tint = 0xFF0000; } playerFleetStatus.addChild(shipIcon); playerFleetDisplay.push(shipIcon); } // Update enemy fleet status for (var i = 0; i < enemyGrid.ships.length; i++) { var ship = enemyGrid.ships[i]; var statusText = new Text2(shipTypes[i] + ' (' + ship.length + ')', { size: 28, fill: ship.sunk ? 0xFF0000 : 0xFFFFFF }); statusText.anchor.set(0, 0); statusText.x = -100; statusText.y = i * 35; enemyFleetStatus.addChild(statusText); enemyFleetDisplay.push(statusText); // Add ship icon var shipIcon = LK.getAsset(ship.type, { width: 30, height: 8, anchorX: 0, anchorY: 0, x: 120, y: i * 35 + 5 }); if (ship.sunk) { shipIcon.tint = 0xFF0000; } enemyFleetStatus.addChild(shipIcon); enemyFleetDisplay.push(shipIcon); } } // Initial setup updateStatusText(); game.update = function () { // Game loop updates };
===================================================================
--- original.js
+++ change.js
@@ -157,9 +157,10 @@
var waterTile = self.attachAsset('water', {
width: cellSize,
height: cellSize,
x: 0,
- y: 0
+ y: 0,
+ color: 0xffffff
});
var shipGraphic = null;
var hitMarker = null;
var missMarker = null;
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