|
|
@ -138,6 +138,7 @@ GameResult checkGameResult(const TicTacToeGame* game) { |
|
|
|
return draw ? GAME_DRAW : SUCCESS; |
|
|
|
} |
|
|
|
|
|
|
|
//Nach eingabe zurberechnung der Minen anzahl |
|
|
|
int calculate_mines(int height, int width) { |
|
|
|
int num_mines; |
|
|
|
if (height <= 1 || width <= 1) { |
|
|
@ -149,6 +150,7 @@ int calculate_mines(int height, int width) { |
|
|
|
return num_mines; |
|
|
|
} |
|
|
|
|
|
|
|
//Zum erstellen des Spielfeldes |
|
|
|
char** create_minefield(int height, int width, char within) { |
|
|
|
char** minefield = (char**)calloc(height, sizeof(char*)); |
|
|
|
for (int i = 0; i < height; i++) { |
|
|
@ -162,6 +164,7 @@ char** create_minefield(int height, int width, char within) { |
|
|
|
return minefield; |
|
|
|
} |
|
|
|
|
|
|
|
//Zum Verteilen der Minen |
|
|
|
void distribute_mines(char** mines, int height, int width, int num_mines) { |
|
|
|
int i, rand_height, rand_width; |
|
|
|
|
|
|
@ -179,6 +182,7 @@ void distribute_mines(char** mines, int height, int width, int num_mines) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//User das Minenfeld zu zeigen |
|
|
|
void show_minefield(char** minefield, int height, int width) { |
|
|
|
int i, j; |
|
|
|
|
|
|
@ -214,18 +218,16 @@ void show_minefield(char** minefield, int height, int width) { |
|
|
|
printf("\n\n"); |
|
|
|
} |
|
|
|
|
|
|
|
//Ist keine Mine in der nähe wird die freie Fläche erweitert |
|
|
|
int field_check(char** minefield, char** mines, int height, int width, int row, int column) { |
|
|
|
char counter = 0; |
|
|
|
if ((row < 0) || (row >= height) || (column < 0) || (column >= width)) { |
|
|
|
printf("Exception: Outside the minefield!\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
// If there is a mine at this position |
|
|
|
if (mines[row][column] == 1) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
// If there is no mine at the position, count how many mines are around it |
|
|
|
if ((row + 1 < height) && (mines[row + 1][column] == 1)) { |
|
|
|
counter++; |
|
|
|
} |
|
|
@ -291,6 +293,7 @@ int field_check(char** minefield, char** mines, int height, int width, int row, |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
//Überprüfe ob eine Mine getroffen wurde |
|
|
|
int end_check(char** minefield, char** mines, int height, int width) { |
|
|
|
int i, j; |
|
|
|
for (i = 0; i < height; i++) { |
|
|
@ -304,6 +307,7 @@ int end_check(char** minefield, char** mines, int height, int width) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
//befreie anliegendes Feld |
|
|
|
void free_minefield(char** minefield, int height) { |
|
|
|
int i; |
|
|
|
// Free each vector |
|
|
|