Browse Source

refactoring : Zeillen abstandverbessert um Code übersichtlicher zumachen

remotes/origin/Daniel
Daniel M 11 months ago
parent
commit
0a66dce53b
  1. BIN
      build/test/out/c/duellist-spielesammlung-projekt.o
  2. BIN
      build/test/out/test_duellist_spielesammlung_projekt.out
  3. 2
      build/test/results/test_duellist_spielesammlung_projekt.pass
  4. 11
      src/main/duellist-spielesammlung-projekt.c

BIN
build/test/out/c/duellist-spielesammlung-projekt.o

BIN
build/test/out/test_duellist_spielesammlung_projekt.out

2
build/test/results/test_duellist_spielesammlung_projekt.pass

@ -115,4 +115,4 @@
:failed: 0 :failed: 0
:ignored: 0 :ignored: 0
:stdout: [] :stdout: []
:time: 0.0499390999998468
:time: 0.05679710000003979

11
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) { int field_check(char** minefield, char** mines, int height, int width, int row, int column) {
char counter = 0; char counter = 0;
if ((row < 0) || (row >= height) || (column < 0) || (column >= width)) { if ((row < 0) || (row >= height) || (column < 0) || (column >= width)) {
printf("Exception: Outside the minefield!\n"); printf("Exception: Outside the minefield!\n");
return -1; 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)) { 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); field_check(minefield, mines, height, width, row - 1, column - 1);
} }
return 1; return 1;
} }
int end_check(char** minefield, char** mines, int height, int width) { int end_check(char** minefield, char** mines, int height, int width) {
int i, j; int i, j;
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) { for (j = 0; j < width; j++) {
// If a field is not uncovered and does not contain a mine, the game is not over // 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; return 1;
} }
@ -324,6 +320,7 @@ int minesweeper() {
scanf("%d", &height); scanf("%d", &height);
printf("Enter the width of the game field:\n"); printf("Enter the width of the game field:\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("Invalid field dimensions.\n");
return 1; return 1;
@ -331,21 +328,21 @@ int minesweeper() {
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("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("There are %d mines on the game field.\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);
char** mines = create_minefield(height, width, 0); char** mines = create_minefield(height, width, 0);
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("Enter 'row column' to uncover (to quit enter '0 0'):\n");
if (scanf("%d %d", &row, &column) != 2) { if (scanf("%d %d", &row, &column) != 2) {
printf("Incorrect input!\n"); printf("Incorrect input!\n");
return 1; return 1;
} }
row--; row--;
column--; column--;
// Quit // Quit
if ((row == -1) && (column == -1)) { if ((row == -1) && (column == -1)) {
break; break;

Loading…
Cancel
Save