
jesteś tutaj
393
Łączenie wszystkiego w całość
Dokończenie metody generateShip
Po dodaniu tego kodu pozostaje jedynie upewnić się, że zarówno początkowe pole zajmowane
przez okręt, jak i dwa pozostałe zostaną zapisane w tablicy
QHZ6KLS/RFDWLRQV
.
generateShip: function() {
var direction = Math.floor(Math.random() * 2);
var row, col;
if (direction === 1) {
row = Math.floor(Math.random() * this.boardSize);
col = Math.floor(Math.random() * (this.boardSize - this.shipLength));
} else {
row = Math.floor(Math.random() * (this.boardSize - this.shipLength));
col = Math.floor(Math.random() * this.boardSize);
}
var newShipLocations = [];
for (var i = 0; i ...