diff --git a/Minesweeper/Core/Inc/spielfeld.h b/Minesweeper/Core/Inc/spielfeld.h index 89540a1..d1fddc0 100644 --- a/Minesweeper/Core/Inc/spielfeld.h +++ b/Minesweeper/Core/Inc/spielfeld.h @@ -34,8 +34,8 @@ void placeBombs(int** gameBoard, int size, int numBombs); void displayGameBoardUART(int** gameBoard, int size); void freeGameBoard(int** gameBoard, int size); int** createHiddenGameBoard(int** gameBoard, int size); -int** revealCell(int** gameBoard, int** hiddenGameBoard, int size, char* position); -void getPositionIndices(char* position, Position* pos); +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); #endif /* INC_SPIELFELD_H_ */ diff --git a/Minesweeper/Core/Src/main.c b/Minesweeper/Core/Src/main.c index 8cc4354..23223a7 100644 --- a/Minesweeper/Core/Src/main.c +++ b/Minesweeper/Core/Src/main.c @@ -107,7 +107,7 @@ int main(void) hiddenGameBoard= createHiddenGameBoard(gameBoard, size); displayGameBoardUART(hiddenGameBoard, size); - hiddenGameBoard= revealCell(gameBoard, hiddenGameBoard, size, "C3"); + hiddenGameBoard= revealCell(gameBoard, hiddenGameBoard, size, 3, 5); displayGameBoardUART(hiddenGameBoard, size); /* USER CODE END 2 */ diff --git a/Minesweeper/Core/Src/spielfeld.c b/Minesweeper/Core/Src/spielfeld.c index f83434c..7ac3ca6 100644 --- a/Minesweeper/Core/Src/spielfeld.c +++ b/Minesweeper/Core/Src/spielfeld.c @@ -8,8 +8,6 @@ #include "spielfeld.h" #include "main.h" -/*Test*/ - int** generateGameBoard(int size) { // Speicher für das Spielfeld reservieren int** gameBoard = (int**)malloc(size * sizeof(int*)); @@ -74,8 +72,6 @@ void placeBombs(int** gameBoard, int size, int numBombs) { } } - - void displayGameBoardUART(int** gameBoard, int size) { // Leere den Empfangspuffer der UART-Schnittstelle clearSerialBuffer(&huart2); @@ -143,10 +139,7 @@ int** createHiddenGameBoard(int** gameBoard, int size) { return hiddenGameBoard; } -void getPositionIndices(char* position, Position* pos) { - pos->col = toupper(position[0]) - 'A'; // Spaltenindex - pos->row = atoi(&position[1]) - 1; // Zeilenindex (von 0-basiert auf 1-basiert) -} + void getNewPosition(Position* pos, int dx, int dy, Position* newPos) { newPos->col = pos->col + dy; @@ -176,9 +169,10 @@ void revealEmptyCells(int** gameBoard, int** hiddenGameBoard, int size, Position } } -int** revealCell(int** gameBoard, int** hiddenGameBoard, int size, char* position) { +int** revealCell(int** gameBoard, int** hiddenGameBoard, int size, int row, int col) { Position pos; - getPositionIndices(position, &pos); + pos.row = row - 1; + pos.col = col - 1; // Überprüfen, ob die Position im gültigen Bereich liegt if (pos.row < 0 || pos.row >= size || pos.col < 0 || pos.col >= size) { @@ -203,3 +197,11 @@ int** revealCell(int** gameBoard, int** hiddenGameBoard, int size, char* positio return hiddenGameBoard; } +void setFlag(int** hiddenGameBoard, int row, int col) { + if (hiddenGameBoard[row][col] = '?'){ + hiddenGameBoard[row][col] = '#'; + } + else{ + hiddenGameBoard[row][col] = '?'; + } +}