diff --git a/Minesweeper/Core/Src/spielfeld.c b/Minesweeper/Core/Src/spielfeld.c index 355b65f..89b9183 100644 --- a/Minesweeper/Core/Src/spielfeld.c +++ b/Minesweeper/Core/Src/spielfeld.c @@ -190,6 +190,9 @@ void revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int c printf("Position bereits aufgedeckt\n"); return hiddenGameBoard; } + if (gameBoard[pos.row][pos.col] == BOMB_CELL) { + handleBombExplode(); + } // Wenn die Zelle leer ist, müssen auch benachbarte leere Zellen aufgedeckt werden if (gameBoard[pos.row][pos.col] == EMPTY_CELL) { @@ -215,6 +218,35 @@ void setFlag(int** hiddenGameBoard, int row, int col, int* numFlags) { } } -void checkWin(){ +bool checkWin(int** gameBoard, int** hiddenGameBoard, int size, int numBombs, int numFlags) { + // Überprüfen, ob alle Bombenpositionen mit einer Flagge markiert wurden + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + if (gameBoard[i][j] == BOMB_CELL && hiddenGameBoard[i][j] != FLAG_CELL) { + return false; // Nicht gewonnen, da nicht alle Bomben markiert sind + } + } + } + + // Überprüfen, ob alle nicht-Bombenfelder aufgedeckt wurden + int totalCells = size * size; + int uncoveredCells = 0; + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + if (gameBoard[i][j] != BOMB_CELL && hiddenGameBoard[i][j] != HIDDEN_CELL) { + uncoveredCells++; + } + } + } + + // Das Spiel ist gewonnen, wenn alle nicht-Bombenfelder aufgedeckt wurden und alle Bomben mit einer Flagge markiert wurden + return uncoveredCells == totalCells - numBombs && numFlags == numBombs; +} + +void handleBombExploded() +{ + +} + }