diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index fd58cfe..85dc9d1 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -75,6 +75,8 @@ void game_minesweeper(){ bool running = true; int x, y, t; Minesweeper_Board board = initialize_minesweeper(); + place_bombs(&board); + while (running){ system("clear"); draw_minesweeper(board); @@ -82,9 +84,10 @@ void game_minesweeper(){ printf("Next turn (x, y, t(0 = open, 1 = flag)): "); scanf("%d %d %d", &x, &y, &t); getchar(); - if(t == 1){board.tiles[x + y * board.width] = board.tiles[x + y * board.width] == EMPTY ? EMPTY : board.tiles[x + y * board.width] == FLAG ? BLOCK : FLAG;} - - + if(x < board.width && y < board.height){ + x = x + y * board.width; + if(t == 1){board.tiles[x] = board.tiles[x] == FLAG ? BLOCK : board.tiles[x] == BLOCK ? FLAG : board.tiles[x];} + } if (t == 2){break;} } } @@ -149,12 +152,12 @@ Minesweeper_Board initialize_minesweeper(){ board.tiles = (char*) malloc(width * height * sizeof(char)); for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;} board.num_bombs = num_bombs; - place_bombs(&board); + board.bombs = (int*) malloc(board.num_bombs * sizeof(int)); + for(int i = 0; i < num_bombs; i++){board.bombs[i] = -1;} return board; } void place_bombs(Minesweeper_Board *board){ - board->bombs = (int*) malloc(board->num_bombs * sizeof(int)); srand(time(NULL)); int r; for(int i = 0; i < board->num_bombs; i++){