|
|
|
@ -8,8 +8,6 @@
|
|
|
|
#include "spielfeld.h"
|
|
|
|
#include "spielfeld.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*Test*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int** generateGameBoard(int size) {
|
|
|
|
int** generateGameBoard(int size) {
|
|
|
|
// Speicher für das Spielfeld reservieren
|
|
|
|
// Speicher für das Spielfeld reservieren
|
|
|
|
int** gameBoard = (int**)malloc(size * sizeof(int*));
|
|
|
|
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) {
|
|
|
|
void displayGameBoardUART(int** gameBoard, int size) {
|
|
|
|
// Leere den Empfangspuffer der UART-Schnittstelle
|
|
|
|
// Leere den Empfangspuffer der UART-Schnittstelle
|
|
|
|
clearSerialBuffer(&huart2);
|
|
|
|
clearSerialBuffer(&huart2);
|
|
|
|
@ -143,10 +139,7 @@ int** createHiddenGameBoard(int** gameBoard, int size) {
|
|
|
|
return hiddenGameBoard;
|
|
|
|
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) {
|
|
|
|
void getNewPosition(Position* pos, int dx, int dy, Position* newPos) {
|
|
|
|
newPos->col = pos->col + dy;
|
|
|
|
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;
|
|
|
|
Position pos;
|
|
|
|
getPositionIndices(position, &pos);
|
|
|
|
pos.row = row - 1;
|
|
|
|
|
|
|
|
pos.col = col - 1;
|
|
|
|
|
|
|
|
|
|
|
|
// Überprüfen, ob die Position im gültigen Bereich liegt
|
|
|
|
// Überprüfen, ob die Position im gültigen Bereich liegt
|
|
|
|
if (pos.row < 0 || pos.row >= size || pos.col < 0 || pos.col >= size) {
|
|
|
|
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;
|
|
|
|
return hiddenGameBoard;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setFlag(int** hiddenGameBoard, int row, int col) {
|
|
|
|
|
|
|
|
if (hiddenGameBoard[row][col] = '?'){
|
|
|
|
|
|
|
|
hiddenGameBoard[row][col] = '#';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
hiddenGameBoard[row][col] = '?';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|