This commit is contained in:
Patrick 2025-01-05 21:06:34 +01:00
parent fec941e502
commit 0754689f33

View file

@ -36,7 +36,7 @@ class Minesweeper {
for (let i = 0; i < this.bombAmount; i++) {
let x = Math.floor(Math.random() * this.width);
let y = Math.floor(Math.random() * this.height);
this.bombs[x][y] && this.field[x][y] != 0 ? i-- : this.bombs[x][y] = true;
(this.bombs[x][y] || this.field[x][y] == 0) ? i-- : this.bombs[x][y] = true;
}
this.firstClick = true;
}
@ -58,11 +58,14 @@ class Minesweeper {
for (let y = 0; y < this.field[x].length; y++) {
if (this.field[x][y] != 0 && !this.bombs[x][y]) {
return;
} else if (this.field[x][y] == 0 && this.bombs[x][y]) {
alert(`[ERROR]: Square (${x}|${y}) should not be a bomb!`);
this.bombs[x][y] = false;
}
}
}
this.drawField();
alert("You won!");
alert('You won!');
window.location.reload();
}
@ -88,7 +91,7 @@ class Minesweeper {
uncoverSquare(x, y) {
if (x < this.field.length && x >= 0 && y < this.field[0].length && y >= 0) {
if (this.bombs[x][y] && this.field[x][y] == 1) {
alert("You lost!");
alert('You lost!');
window.location.reload();
} else if (this.field[x][y] == 1) {
this.field[x][y] = 0;