|
|
@ -226,7 +226,7 @@ void show_minefield(char** minefield, int height, int width) { |
|
|
|
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"); |
|
|
|
printf("Auserhalb des Minenfeldes!\n"); |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
@ -303,7 +303,6 @@ int end_check(char** minefield, char** mines, int height, int width) { |
|
|
|
int i, j; |
|
|
|
for (i = 0; i < height; i++) { |
|
|
|
for (j = 0; j < width; j++) { |
|
|
|
// If a field is not uncovered and does not contain a mine, the game is not over |
|
|
|
if ((mines[i][j] == 0) && (minefield[i][j] == unknown_character)) { |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -315,7 +314,6 @@ int end_check(char** minefield, char** mines, int height, int width) { |
|
|
|
//befreie anliegendes Feld |
|
|
|
void free_minefield(char** minefield, int height) { |
|
|
|
int i; |
|
|
|
// Free each vector |
|
|
|
for (i = 0; i < height; i++) { |
|
|
|
free(minefield[i]); |
|
|
|
} |
|
|
@ -323,6 +321,7 @@ void free_minefield(char** minefield, int height) { |
|
|
|
minefield = NULL; |
|
|
|
} |
|
|
|
|
|
|
|
//Start des Spiels |
|
|
|
int minesweeper() { |
|
|
|
int height, width, row, column; |
|
|
|
printf("Geben Sie die Grösse des spielfeldes ein:\n"); |
|
|
@ -338,7 +337,6 @@ int minesweeper() { |
|
|
|
printf("Das spielfeld hat eine groesse von >%d< und eine breite von: >%d<.\n", height, width); |
|
|
|
printf("Es gibt %d Minen auf dem Spielfeld.\n", num_mines); |
|
|
|
|
|
|
|
// Matrix for the game field |
|
|
|
char** minefield = create_minefield(height, width, unknown_character); |
|
|
|
char** mines = create_minefield(height, width, 0); |
|
|
|
|
|
|
@ -352,11 +350,10 @@ int minesweeper() { |
|
|
|
} |
|
|
|
row--; |
|
|
|
column--; |
|
|
|
// Quit |
|
|
|
|
|
|
|
if ((row == -1) && (column == -1)) { |
|
|
|
break; |
|
|
|
} |
|
|
|
// Check field boundaries |
|
|
|
if (row >= height || row < 0) { |
|
|
|
printf("hoehe zwischen 1 und %d!\n", height); |
|
|
|
continue; |
|
|
@ -366,21 +363,18 @@ int minesweeper() { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Did you land on a mine? |
|
|
|
if (field_check(minefield, mines, height, width, row, column) == 0) { |
|
|
|
// Show the mines |
|
|
|
show_minefield(mines, height, width); |
|
|
|
printf("höhe: %d breite: %d war leider eine mine!\n", row + 1, column + 1); |
|
|
|
break; |
|
|
|
} |
|
|
|
// Are you done? |
|
|
|
|
|
|
|
else if (end_check(minefield, mines, height, width)) { |
|
|
|
// Show the mines |
|
|
|
show_minefield(mines, height, width); |
|
|
|
printf("Sie haben es erfolgreich geloesst!\n"); |
|
|
|
break; |
|
|
|
} |
|
|
|
// Show current field to continue playing |
|
|
|
|
|
|
|
else { |
|
|
|
show_minefield(mines, height, width); |
|
|
|
} |
|
|
|