diff --git a/build/test/out/c/duellist-spielesammlung-projekt.o b/build/test/out/c/duellist-spielesammlung-projekt.o index c4f8ca1..ba37b1f 100644 Binary files a/build/test/out/c/duellist-spielesammlung-projekt.o and b/build/test/out/c/duellist-spielesammlung-projekt.o differ diff --git a/build/test/out/test_duellist_spielesammlung_projekt.out b/build/test/out/test_duellist_spielesammlung_projekt.out index 931e953..5169aa3 100644 Binary files a/build/test/out/test_duellist_spielesammlung_projekt.out and b/build/test/out/test_duellist_spielesammlung_projekt.out differ diff --git a/build/test/results/test_duellist_spielesammlung_projekt.pass b/build/test/results/test_duellist_spielesammlung_projekt.pass index 03dadd2..c0b331f 100644 --- a/build/test/results/test_duellist_spielesammlung_projekt.pass +++ b/build/test/results/test_duellist_spielesammlung_projekt.pass @@ -115,4 +115,4 @@ :failed: 0 :ignored: 0 :stdout: [] -:time: 0.0499390999998468 +:time: 0.05679710000003979 diff --git a/src/main/duellist-spielesammlung-projekt.c b/src/main/duellist-spielesammlung-projekt.c index d0a7c8b..df02795 100644 --- a/src/main/duellist-spielesammlung-projekt.c +++ b/src/main/duellist-spielesammlung-projekt.c @@ -216,7 +216,6 @@ 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"); return -1; @@ -289,13 +288,11 @@ int field_check(char** minefield, char** mines, int height, int width, int row, if ((row - 1 >= 0) && (column - 1 >= 0) && (minefield[row - 1][column - 1] == unknown_character) && (mines[row - 1][column - 1] == 0)) { field_check(minefield, mines, height, width, row - 1, column - 1); } - return 1; } 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 @@ -304,7 +301,6 @@ int end_check(char** minefield, char** mines, int height, int width) { } } } - return 1; } @@ -324,6 +320,7 @@ int minesweeper() { scanf("%d", &height); printf("Enter the width of the game field:\n"); scanf("%d", &width); + if (height <= 0 || width <= 0 || height > max_height || width > max_width) { printf("Invalid field dimensions.\n"); return 1; @@ -331,21 +328,21 @@ int minesweeper() { 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); + // Matrix for the game field char** minefield = create_minefield(height, width, unknown_character); char** mines = create_minefield(height, width, 0); + distribute_mines(mines, height, width, num_mines); - while (1) { + while (1) { printf("Enter 'row column' to uncover (to quit enter '0 0'):\n"); if (scanf("%d %d", &row, &column) != 2) { printf("Incorrect input!\n"); return 1; } - row--; column--; - // Quit if ((row == -1) && (column == -1)) { break;