абоба
This commit is contained in:
@@ -1,108 +0,0 @@
|
|||||||
window.onload = function () {
|
|
||||||
|
|
||||||
var shots = 0;
|
|
||||||
var hits = 0;
|
|
||||||
var maxShots = 35;
|
|
||||||
var gameOver = false;
|
|
||||||
|
|
||||||
var record = localStorage.getItem("record") || "-";
|
|
||||||
document.getElementById("record").innerHTML = "RECORD: " + record;
|
|
||||||
|
|
||||||
var sea = [];
|
|
||||||
|
|
||||||
var sea = [
|
|
||||||
[null, null, null, null, null, null, null, null],
|
|
||||||
[null, 0, 0, 0, 0, 0, 0, 0],
|
|
||||||
[null, 0, 0, 0, 0, 0, 0, 0],
|
|
||||||
[null, 0, 0, 0, 0, 0, 0, 0],
|
|
||||||
[null, 0, 0, 0, 0, 0, 0, 0],
|
|
||||||
[null, 0, 0, 0, 0, 0, 0, 0],
|
|
||||||
[null, 0, 0, 0, 0, 0, 0, 0],
|
|
||||||
[null, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
];
|
|
||||||
|
|
||||||
function createShip() {
|
|
||||||
|
|
||||||
var x, y;
|
|
||||||
|
|
||||||
do {
|
|
||||||
x = Math.floor(Math.random() * 5) + 1;
|
|
||||||
y = Math.floor(Math.random() * 7) + 1;
|
|
||||||
|
|
||||||
} while (
|
|
||||||
sea[y][x] == 1 ||
|
|
||||||
sea[y][x + 1] == 1 ||
|
|
||||||
sea[y][x + 2] == 1
|
|
||||||
);
|
|
||||||
|
|
||||||
sea[y][x] = 1;
|
|
||||||
sea[y][x + 1] = 1;
|
|
||||||
sea[y][x + 2] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 5; i++) {
|
|
||||||
createShip();
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("FIELD:");
|
|
||||||
console.log(sea);
|
|
||||||
|
|
||||||
var table = document.getElementById("board");
|
|
||||||
|
|
||||||
for (var i = 1; i <= 7; i++) {
|
|
||||||
|
|
||||||
var row = document.createElement("tr");
|
|
||||||
|
|
||||||
for (var j = 1; j <= 7; j++) {
|
|
||||||
|
|
||||||
var cell = document.createElement("td");
|
|
||||||
|
|
||||||
cell.dataset.y = i;
|
|
||||||
cell.dataset.x = j;
|
|
||||||
|
|
||||||
cell.onclick = function () {
|
|
||||||
|
|
||||||
if (gameOver || this.innerHTML != "") return;
|
|
||||||
|
|
||||||
var y = this.dataset.y;
|
|
||||||
var x = this.dataset.x;
|
|
||||||
|
|
||||||
shots++;
|
|
||||||
document.getElementById("shots").innerHTML =
|
|
||||||
"SHOTS: " + shots + " / " + maxShots;
|
|
||||||
|
|
||||||
if (sea[y][x] == 1) {
|
|
||||||
|
|
||||||
this.innerHTML = "X";
|
|
||||||
sea[y][x] = 0;
|
|
||||||
hits++;
|
|
||||||
|
|
||||||
if (hits == 15) {
|
|
||||||
|
|
||||||
alert("ВЫ ВЫИГРАЛИ");
|
|
||||||
|
|
||||||
if (record == "-" || shots < record) {
|
|
||||||
localStorage.setItem("record", shots);
|
|
||||||
}
|
|
||||||
|
|
||||||
gameOver = true;
|
|
||||||
location.reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this.innerHTML = "O";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shots > maxShots && hits < 15) {
|
|
||||||
alert("ВЫ ПРОИГРАЛИ");
|
|
||||||
gameOver = true;
|
|
||||||
location.reload();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
row.appendChild(cell);
|
|
||||||
}
|
|
||||||
|
|
||||||
table.appendChild(row);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
window.onload = function () {
|
||||||
|
|
||||||
|
var shots = 0;
|
||||||
|
var hits = 0;
|
||||||
|
var maxShots = 35;
|
||||||
|
var gameOver = false;
|
||||||
|
|
||||||
|
var x1 = Math.floor(Math.random() * 5) + 1;
|
||||||
|
var x2 = x1 + 1;
|
||||||
|
var x3 = x1 + 2;
|
||||||
|
var guess;
|
||||||
|
var hits = 0;
|
||||||
|
var guesses = 0;
|
||||||
|
var isSunk = false;
|
||||||
|
var y1 = Math.floor(Math.random() * 7) + 1;
|
||||||
|
var sea = [
|
||||||
|
[null, null, null, null, null, null, null, null],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
];
|
||||||
|
|
||||||
|
var record = localStorage.getItem("record") || "-";
|
||||||
|
document.getElementById("record").innerHTML = "RECORD: " + record;
|
||||||
|
|
||||||
|
var sea = [];
|
||||||
|
|
||||||
|
var sea = [
|
||||||
|
[null, null, null, null, null, null, null, null],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[null, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
];
|
||||||
|
|
||||||
|
function createShip() {
|
||||||
|
|
||||||
|
var x, y;
|
||||||
|
|
||||||
|
do {
|
||||||
|
x = Math.floor(Math.random() * 5) + 1;
|
||||||
|
y = Math.floor(Math.random() * 7) + 1;
|
||||||
|
|
||||||
|
} while (
|
||||||
|
sea[y][x] == 1 ||
|
||||||
|
sea[y][x + 1] == 1 ||
|
||||||
|
sea[y][x + 2] == 1
|
||||||
|
);
|
||||||
|
|
||||||
|
sea[y][x] = 1;
|
||||||
|
sea[y][x + 1] = 1;
|
||||||
|
sea[y][x + 2] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
|
createShip();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("FIELD:");
|
||||||
|
console.log(sea);
|
||||||
|
|
||||||
|
var table = document.getElementById("board");
|
||||||
|
|
||||||
|
for (var i = 1; i <= 7; i++) {
|
||||||
|
|
||||||
|
var row = document.createElement("tr");
|
||||||
|
|
||||||
|
for (var j = 1; j <= 7; j++) {
|
||||||
|
|
||||||
|
var cell = document.createElement("td");
|
||||||
|
|
||||||
|
cell.dataset.y = i;
|
||||||
|
cell.dataset.x = j;
|
||||||
|
|
||||||
|
cell.onclick = function () {
|
||||||
|
|
||||||
|
if (gameOver || this.innerHTML != "") return;
|
||||||
|
|
||||||
|
var y = this.dataset.y;
|
||||||
|
var x = this.dataset.x;
|
||||||
|
|
||||||
|
shots++;
|
||||||
|
document.getElementById("shots").innerHTML =
|
||||||
|
"SHOTS: " + shots + " / " + maxShots;
|
||||||
|
|
||||||
|
if (sea[y][x] == 1) {
|
||||||
|
|
||||||
|
this.innerHTML = "X";
|
||||||
|
sea[y][x] = 0;
|
||||||
|
hits++;
|
||||||
|
|
||||||
|
if (hits == 15) {
|
||||||
|
|
||||||
|
alert("ВЫ ВЫИГРАЛИ");
|
||||||
|
|
||||||
|
if (record == "-" || shots < record) {
|
||||||
|
localStorage.setItem("record", shots);
|
||||||
|
}
|
||||||
|
|
||||||
|
gameOver = true;
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.innerHTML = "O";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shots > maxShots && hits < 15) {
|
||||||
|
alert("ВЫ ПРОИГРАЛИ");
|
||||||
|
gameOver = true;
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
row.appendChild(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
table.appendChild(row);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
console.log(sea[1]);
|
||||||
|
console.log(sea[2]);
|
||||||
|
console.log(sea[3]);
|
||||||
|
console.log(sea[4]);
|
||||||
|
console.log(sea[5]);
|
||||||
|
console.log(sea[6]);
|
||||||
|
console.log(sea[7]);
|
||||||
|
console.log(sea);
|
||||||
|
console.log(x1, x2, x3);
|
||||||
|
console.log(y1);
|
||||||
Reference in New Issue
Block a user