|
|
|
|
@ -174,7 +174,7 @@ void revealEmptyCells(int** gameBoard, int** hiddenGameBoard, int size, Position
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int col) {
|
|
|
|
|
int revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int col) {
|
|
|
|
|
Position pos;
|
|
|
|
|
pos.row = row;
|
|
|
|
|
pos.col = col;
|
|
|
|
|
@ -182,16 +182,17 @@ void revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int c
|
|
|
|
|
// Überprüfen, ob die Position im gültigen Bereich liegt
|
|
|
|
|
if (pos.row < 0 || pos.row >= size || pos.col < 0 || pos.col >= size) {
|
|
|
|
|
printf("Ungültige Position\n");
|
|
|
|
|
return hiddenGameBoard;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Überprüfen, ob die Zelle bereits aufgedeckt ist
|
|
|
|
|
if (hiddenGameBoard[pos.row][pos.col] != HIDDEN_CELL) {
|
|
|
|
|
printf("Position bereits aufgedeckt\n");
|
|
|
|
|
return hiddenGameBoard;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (gameBoard[pos.row][pos.col] == BOMB_CELL) {
|
|
|
|
|
handleBombExploded();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Wenn die Zelle leer ist, müssen auch benachbarte leere Zellen aufgedeckt werden
|
|
|
|
|
@ -201,8 +202,7 @@ void revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int c
|
|
|
|
|
// Aufdecken der Zelle im verdeckten Spielfeld
|
|
|
|
|
hiddenGameBoard[pos.row][pos.col] = gameBoard[pos.row][pos.col];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hiddenGameBoard;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setFlag(int** hiddenGameBoard, int row, int col, int* numFlags) {
|
|
|
|
|
@ -240,11 +240,16 @@ int checkWin(int** gameBoard, int** hiddenGameBoard, int size, int numBombs, int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Das Spiel ist gewonnen, wenn alle nicht-Bombenfelder aufgedeckt wurden und alle Bomben mit einer Flagge markiert wurden
|
|
|
|
|
if (uncoveredCells == totalCells - numBombs && numFlags == numBombs) {
|
|
|
|
|
char message[] = "Herzlichen Glückwunsch! Du hast gewonnen! Starte neu mit der ON Taste.\r\n";
|
|
|
|
|
HAL_UART_Transmit(&huart2, (uint8_t*)message, sizeof(message), 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return uncoveredCells == totalCells - numBombs && numFlags == numBombs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleBombExploded() {
|
|
|
|
|
char message[] = "Game Over! You hit a bomb.\r\n";
|
|
|
|
|
char message[] = "Spiel Verloren! Du hast eine Bombe getroffen\r\n";
|
|
|
|
|
HAL_UART_Transmit(&huart2, (uint8_t*)message, sizeof(message), 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|