diff --git a/Minesweeper/Core/Inc/spielfeld.h b/Minesweeper/Core/Inc/spielfeld.h index b7e403f..f86119d 100644 --- a/Minesweeper/Core/Inc/spielfeld.h +++ b/Minesweeper/Core/Inc/spielfeld.h @@ -32,7 +32,7 @@ typedef struct { int** generateGameBoard(int size); void placeBombs(int** gameBoard, int size, int numBombs); -void displayGameBoardUART(int** gameBoard, int size); +void displayGameBoardUART(int** gameBoard, int size, int numBombs, int numFlags); void freeGameBoard(int** gameBoard, int size); int** createHiddenGameBoard(int** gameBoard, int size); int** revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int col); diff --git a/Minesweeper/Core/Src/main.c b/Minesweeper/Core/Src/main.c index 23223a7..ebbc4f9 100644 --- a/Minesweeper/Core/Src/main.c +++ b/Minesweeper/Core/Src/main.c @@ -72,6 +72,7 @@ int main(void) /* USER CODE BEGIN 1 */ int size = 12; int numBombs = 10; + int numFlags = 0; int hiddenGameBoard = 0; int** gameBoard = (int**)malloc(size * sizeof(int*)); @@ -102,13 +103,15 @@ int main(void) gameBoard= generateGameBoard(size); placeBombs(gameBoard, size, numBombs); clearSerialOutput(); - displayGameBoardUART(gameBoard, size); + displayGameBoardUART(gameBoard, size, numBombs, numFlags); hiddenGameBoard= createHiddenGameBoard(gameBoard, size); - displayGameBoardUART(hiddenGameBoard, size); + displayGameBoardUART(hiddenGameBoard, size, numBombs, numFlags); hiddenGameBoard= revealCell(gameBoard, hiddenGameBoard, size, 3, 5); - displayGameBoardUART(hiddenGameBoard, size); + hiddenGameBoard= setFlag(hiddenGameBoard, 6,7, numFlags); + + displayGameBoardUART(hiddenGameBoard, size, numBombs, numFlags); /* USER CODE END 2 */ diff --git a/Minesweeper/Core/Src/spielfeld.c b/Minesweeper/Core/Src/spielfeld.c index 700643a..08cc667 100644 --- a/Minesweeper/Core/Src/spielfeld.c +++ b/Minesweeper/Core/Src/spielfeld.c @@ -72,7 +72,7 @@ void placeBombs(int** gameBoard, int size, int numBombs) { } } -void displayGameBoardUART(int** gameBoard, int size) { +void displayGameBoardUART(int** gameBoard, int size, int numBombs, int numFlags) { // Leere den Empfangspuffer der UART-Schnittstelle clearSerialBuffer(&huart2); @@ -108,6 +108,9 @@ void displayGameBoardUART(int** gameBoard, int size) { offset += snprintf(buffer + offset, sizeof(buffer) - offset, "\r\n"); } + // Anzeige der verbleibenden Anzahl von Bomben + offset += snprintf(buffer + offset, sizeof(buffer) - offset, "\r\nVerbleibende Anzahl von Bomben: %d\r\n", numBombs - numFlags); + // Senden des formatierten Strings über UART HAL_UART_Transmit(&huart2, (uint8_t*)buffer, offset, 100); } @@ -173,8 +176,8 @@ void revealEmptyCells(int** gameBoard, int** hiddenGameBoard, int size, Position int** revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int col) { Position pos; - pos.row = row - 1; - pos.col = col - 1; + pos.row = row; + pos.col = col; // Überprüfen, ob die Position im gültigen Bereich liegt if (pos.row < 0 || pos.row >= size || pos.col < 0 || pos.col >= size) { @@ -199,12 +202,15 @@ int** revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int return hiddenGameBoard; } -void setFlag(int** hiddenGameBoard, int row, int col) { +void setFlag(int** hiddenGameBoard, int row, int col, int numFlags) { if (hiddenGameBoard[row][col] == FLAG_CELL) { hiddenGameBoard[row][col] = HIDDEN_CELL; + numFlags --; } - else{ + else if (hiddenGameBoard[row][col] == HIDDEN_CELL){ hiddenGameBoard[row][col] = FLAG_CELL; + numFlags ++; } + return numFlags; }