int function and win condition

master
thunic 2 years ago
parent 46f1cf4143
commit cfe398257a

@ -35,7 +35,7 @@ void placeBombs(int** gameBoard, int size, int numBombs);
void displayGameBoardUART(int** gameBoard, int size, int numBombs, int numFlags);
void freeGameBoard(int** gameBoard, int size);
int** createHiddenGameBoard(int** gameBoard, int size);
void revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int col);
int revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int col);
void getPositionIndices(int row, int col, Position* pos);
void getNewPosition(Position* pos, int dx, int dy, Position* newPos);
void setFlag(int** hiddenGameBoard, int row, int col, int* numFlags);

@ -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);
}

Loading…
Cancel
Save