diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c index 50bb461..43a1eed 100644 --- a/src/main/c/Minesweeper/minesweeper_start.c +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -25,6 +25,7 @@ void place_bombs(Minesweeper_Board *board); bool bomb_in_array(int array[], int bomb, int length); void draw_minesweeper(Minesweeper_Board board); int open_tile(Minesweeper_Board *board, int tile); +int number_of_bombs(Minesweeper_Board *board, int tile); #pragma endregion #pragma region Global @@ -199,5 +200,23 @@ void draw_minesweeper(Minesweeper_Board board){ int open_tile(Minesweeper_Board *board, int tile){ if(bomb_in_array(board->bombs, tile, board->num_bombs)){return -1;} + int num = number_of_bombs(board, tile); +} + +int number_of_bombs(Minesweeper_Board *board, int tile){ + int sum = 0; + for(int i = 0; i < 8; i++){ + int check_tile = tile; + if(i < 3 && tile % board->width == 0){continue;} + else{check_tile - 1;} + if(i > 4 && tile % board->width + 1 == board->width){continue;} + else{check_tile + 1;} + if(i % 3 == 0 && i != 0 && tile / board->width == 0){continue;} + else{check_tile - board->width;} + if(i % 3 == 1 && tile / board->width + 1 == height){continue;} + else{check_tile + board->width;} + if(bomb_in_array(board->bombs, check_tile, board->num_bombs)){sum++;} + } + return sum; } \ No newline at end of file diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h index a73d944..c62977b 100644 --- a/src/main/c/Minesweeper/minesweeper_start.h +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -11,7 +11,9 @@ typedef struct Minesweeper_Board{ void minesweeper_start(); +Minesweeper_Board initialize_minesweeper(); bool bomb_in_array(int array[], int bomb, int length); +int number_of_bombs(Minesweeper_Board *board, int tile); #endif // MINESWEEPER_START_H \ No newline at end of file diff --git a/test/Minesweeper/test_number_of_bombs.c b/test/Minesweeper/test_number_of_bombs.c new file mode 100644 index 0000000..3f899f7 --- /dev/null +++ b/test/Minesweeper/test_number_of_bombs.c @@ -0,0 +1,24 @@ +#ifdef TEST +#include "unity.h" +#include +#include "../../src/main/c/Minesweeper/minesweeper_start.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_no_bombs_placed_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 1 + board.width * 1; + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed +} + +#endif // TEST \ No newline at end of file