From 0754689f33f01b69537a4d0127bd42d079b32b4e Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 5 Jan 2025 21:06:34 +0100 Subject: [PATCH] hotfix --- secret/mineSweeper/script.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/secret/mineSweeper/script.js b/secret/mineSweeper/script.js index 4af555d..d35c436 100644 --- a/secret/mineSweeper/script.js +++ b/secret/mineSweeper/script.js @@ -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;