Position overwrite

master
thunic 2 years ago
parent f5d90ac17f
commit 9a3ce17283

@ -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_ */

@ -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 */

@ -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] = '?';
}
}

Loading…
Cancel
Save