From 3b9e1ac22bd9380f7230c4d4478713450f970a3c Mon Sep 17 00:00:00 2001 From: thunic Date: Sun, 17 Mar 2024 00:27:05 +0100 Subject: [PATCH] win function implemented --- Minesweeper/Core/Src/spielfeld.c | 34 +++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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() +{ + +} + }