commit 017412953745cc8be6f0605b59dc0a6af8ffd202 parent 88f0f76181d45ecd30ad14c80418ba5a699b5e66 Author: Christos Margiolis <christos@margiolis.net> Date: Sat, 11 Jan 2020 00:18:30 +0200 fixed bugs (#1) Diffstat:
5 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/include/minesweeper.h b/assignment-1.5-arrays-pointers-files/minesweeper/include/minesweeper.h @@ -19,10 +19,10 @@ int set_minesnum(struct _win_st*, int); void game_win(int, int, int); void init_dispboard(struct _win_st*, int, int); void fill_dispboard(char **, int, int); -void init_mineboard(struct _win_st*, int, int, int); -void fill_mineboard(char **, int, int, int); -void adj_mines(char **, int, int; +void init_mineboard(struct _win_st*, int, int, int); +void place_mines(char **, int, int, int); +void adj_mines(char **, int, int); void fill_spaces(char **, int, int, int); diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/minesweeper b/assignment-1.5-arrays-pointers-files/minesweeper/minesweeper Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/main.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/main.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/obj/minesweeper.o b/assignment-1.5-arrays-pointers-files/minesweeper/obj/minesweeper.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c b/assignment-1.5-arrays-pointers-files/minesweeper/src/minesweeper.c @@ -108,6 +108,7 @@ void init_dispboard(WINDOW *gameWin, int WIDTH, int HEIGHT) fill_dispboard(dispboard, WIDTH, HEIGHT); print(gameWin, dispboard, WIDTH, HEIGHT); + getchar(); free(dispboard); } @@ -130,7 +131,8 @@ void init_mineboard(WINDOW *gameWin, int WIDTH, int HEIGHT, int MINES) *(mineboard + i) = (char *)malloc(HEIGHT); fill_spaces(mineboard, WIDTH, HEIGHT, MINES); - fill_mineboard(mineboard, WIDTH, HEIGHT, MINES); + place_mines(mineboard, WIDTH, HEIGHT, MINES); + adj_mines(mineboard, WIDTH, HEIGHT); print(gameWin, mineboard, WIDTH, HEIGHT); @@ -138,7 +140,7 @@ void init_mineboard(WINDOW *gameWin, int WIDTH, int HEIGHT, int MINES) } -void fill_mineboard(char **mineboard, int WIDTH, int HEIGHT, int MINES) +void place_mines(char **mineboard, int WIDTH, int HEIGHT, int MINES) { int i, wRand, hRand; @@ -146,13 +148,9 @@ void fill_mineboard(char **mineboard, int WIDTH, int HEIGHT, int MINES) for (i = 0; i < MINES; i++) { - for (int j = 0; j < MINES; j++) - { - wRand = rand() % WIDTH; - hRand = rand() % HEIGHT; - *(*(mineboard + wRand) + hRand) = '*'; - //adj_mines(mineboard, i, j); - } + wRand = rand() % WIDTH; + hRand = rand() % HEIGHT; + *(*(mineboard + wRand) + hRand) = '*'; } } @@ -174,11 +172,19 @@ void fill_mineboard(char **mineboard, int WIDTH, int HEIGHT, int MINES) [x-1, y+1][x, y+1][x+1, y+1] */ -void adj_mines(char **mineboard, int row, int col) +void adj_mines(char **mineboard, int WIDTH, int HEIGHT) { - int numAdj = 0; + int row, col, numAdj = 0; + + for (row = 1; row <= WIDTH; row++) + { + for (col = 1; col <= HEIGHT; col++) + { + if (*(*(mineboard + (row - 1)) + col) != '*') + numAdj++; + } + } - if (*(*(mineboard + (row - 1)) + col) != '*'); }