From e95f7f74d21023ba1029234a3b59ec6a4c1eea03 Mon Sep 17 00:00:00 2001 From: Matti Date: Fri, 15 Nov 2024 23:09:54 +0100 Subject: [PATCH] Bugfixes: Now Always deploys 99 Bombs and doesnt print random number in [0][0] --- Aufg6/MineSweeper.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Aufg6/MineSweeper.cpp b/Aufg6/MineSweeper.cpp index aa84d24..4ae7ce3 100644 --- a/Aufg6/MineSweeper.cpp +++ b/Aufg6/MineSweeper.cpp @@ -18,14 +18,19 @@ struct MineSweeperBoard { } void spreadBombs() { while (bombCounter < 99) { - field[getRandomNumberInRange(0,15)][getRandomNumberInRange(0,15)] = "x"; - bombCounter++; + short x = getRandomNumberInRange(0,15); + short y = getRandomNumberInRange(0,15); + if (field[x][y] != "x") { + field[x][y] = "x"; + bombCounter++; + } } } std::string countNeighbourBombs(int i, int j) { i--; j--; - int counter; + int counter = 0; + // int counter; // Not setting this nerd to 0 can cause a bug for (int k = 0; k < 3; k++) { for (int l = 0; l < 3; l++) { if ((i+k < 16) && (j+l < 16) && (i-l >= 0) && (j-l >= 0)) {