Browse Source

Merge branch 'Daniel' into 'main'

Daniel

See merge request fdai7745/duellist-spielesammlung-projekt!13
remotes/origin/Areeb
fdai7745 11 months ago
parent
commit
3f84225a93
  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. 71
      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

@ -75,4 +75,4 @@
:failed: 0 :failed: 0
:ignored: 0 :ignored: 0
:stdout: [] :stdout: []
:time: 0.04396939999423921
:time: 0.04444100000000617

71
src/main/duellist-spielesammlung-projekt.c

@ -293,6 +293,31 @@ int field_check(char** minefield, char** mines, int height, int width, int row,
return 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
if ((mines[i][j] == 0) && (minefield[i][j] == unknown_character)) {
return 0;
}
}
}
return 1;
}
void free_minefield(char** minefield, int height) {
int i;
// Free each vector
for (i = 0; i < height; i++) {
free(minefield[i]);
}
free(minefield);
minefield = NULL;
}
int minesweeper() { int minesweeper() {
int height, width, row, column; int height, width, row, column;
printf("Enter the height of the game field:\n"); printf("Enter the height of the game field:\n");
@ -310,6 +335,52 @@ int minesweeper() {
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) {
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;
}
// Check field boundaries
if (row >= height || row < 0) {
printf("Row must be between 1 and %d!\n", height);
continue;
}
if (column >= width || column < 0) {
printf("Column must be between 1 and %d!\n", width);
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("Row: %d Column: %d was unfortunately a 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("Great! Solved correctly!\n");
break;
}
// Show current field to continue playing
else {
show_minefield(mines, height, width);
}
}
free_minefield(minefield, height);
free_minefield(mines, height);
return 1; return 1;
} }
Loading…
Cancel
Save