|
@ -225,6 +225,7 @@ int field_check(char** minefield, char** mines, int height, int width, int row, |
|
|
printf("Exception: Outside the minefield!\n"); |
|
|
printf("Exception: Outside the minefield!\n"); |
|
|
return -1; |
|
|
return -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (mines[row][column] == 1) { |
|
|
if (mines[row][column] == 1) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
@ -320,18 +321,18 @@ void free_minefield(char** minefield, int height) { |
|
|
|
|
|
|
|
|
int minesweeper() { |
|
|
int minesweeper() { |
|
|
int height, width, row, column; |
|
|
int height, width, row, column; |
|
|
printf("Enter the height of the game field:\n"); |
|
|
|
|
|
|
|
|
printf("Geben Sie die Grösse des spielfeldes ein:\n"); |
|
|
scanf("%d", &height); |
|
|
scanf("%d", &height); |
|
|
printf("Enter the width of the game field:\n"); |
|
|
|
|
|
|
|
|
printf("Geben Sie breite des Spielfeldes ein:\n"); |
|
|
scanf("%d", &width); |
|
|
scanf("%d", &width); |
|
|
|
|
|
|
|
|
if (height <= 0 || width <= 0 || height > max_height || width > max_width) { |
|
|
if (height <= 0 || width <= 0 || height > max_height || width > max_width) { |
|
|
printf("Invalid field dimensions.\n"); |
|
|
|
|
|
|
|
|
printf("unpassen form gewählt.\n"); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
int num_mines = calculate_mines(height, width); |
|
|
int num_mines = calculate_mines(height, width); |
|
|
printf("The game field is >%d< in height and >%d< in width.\n", height, width); |
|
|
|
|
|
printf("There are %d mines on the game field.\n", num_mines); |
|
|
|
|
|
|
|
|
printf("Das spielfeld hat eine grösse 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 |
|
|
// Matrix for the game field |
|
|
char** minefield = create_minefield(height, width, unknown_character); |
|
|
char** minefield = create_minefield(height, width, unknown_character); |
|
@ -340,9 +341,9 @@ int minesweeper() { |
|
|
distribute_mines(mines, height, width, num_mines); |
|
|
distribute_mines(mines, height, width, num_mines); |
|
|
|
|
|
|
|
|
while (1) { |
|
|
while (1) { |
|
|
printf("Enter 'row column' to uncover (to quit enter '0 0'):\n"); |
|
|
|
|
|
|
|
|
printf("Geben 'vertikale horizonatle' ein um zu spielen Bsp vertikal 0 und horizontal: 0\n"); |
|
|
if (scanf("%d %d", &row, &column) != 2) { |
|
|
if (scanf("%d %d", &row, &column) != 2) { |
|
|
printf("Incorrect input!\n"); |
|
|
|
|
|
|
|
|
printf("Falsche eingabe!\n"); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
row--; |
|
|
row--; |
|
@ -353,11 +354,11 @@ int minesweeper() { |
|
|
} |
|
|
} |
|
|
// Check field boundaries |
|
|
// Check field boundaries |
|
|
if (row >= height || row < 0) { |
|
|
if (row >= height || row < 0) { |
|
|
printf("Row must be between 1 and %d!\n", height); |
|
|
|
|
|
|
|
|
printf("höhe zwischen 1 und %d!\n", height); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
if (column >= width || column < 0) { |
|
|
if (column >= width || column < 0) { |
|
|
printf("Column must be between 1 and %d!\n", width); |
|
|
|
|
|
|
|
|
printf("breite zwischen 1 und %d!\n", width); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -365,14 +366,14 @@ int minesweeper() { |
|
|
if (field_check(minefield, mines, height, width, row, column) == 0) { |
|
|
if (field_check(minefield, mines, height, width, row, column) == 0) { |
|
|
// Show the mines |
|
|
// Show the mines |
|
|
show_minefield(mines, height, width); |
|
|
show_minefield(mines, height, width); |
|
|
printf("Row: %d Column: %d was unfortunately a mine!\n", row + 1, column + 1); |
|
|
|
|
|
|
|
|
printf("höhe: %d breite: %d war leider eine mine!\n", row + 1, column + 1); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
// Are you done? |
|
|
// Are you done? |
|
|
else if (end_check(minefield, mines, height, width)) { |
|
|
else if (end_check(minefield, mines, height, width)) { |
|
|
// Show the mines |
|
|
// Show the mines |
|
|
show_minefield(mines, height, width); |
|
|
show_minefield(mines, height, width); |
|
|
printf("Great! Solved correctly!\n"); |
|
|
|
|
|
|
|
|
printf("Sie haben es erfolgreich gelösst!\n"); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
// Show current field to continue playing |
|
|
// Show current field to continue playing |
|
|