diff options
| author | dawidg81 <dawidgorski.m@gmail.com> | 2026-02-03 11:04:14 +0100 |
|---|---|---|
| committer | dawidg81 <dawidgorski.m@gmail.com> | 2026-02-03 11:04:14 +0100 |
| commit | 2e9b97faf5b5c123da612e4b82c914dcd79bc959 (patch) | |
| tree | b943a3f8436265bb9fb04c6605e86529c08eb928 | |
| parent | 3d9a91fb44c8ae43779e80e12a4a2da87cc9b3b9 (diff) | |
| -rw-r--r-- | src/Game.cpp | 60 | ||||
| -rw-r--r-- | src/Game.hpp | 2 |
2 files changed, 29 insertions, 33 deletions
diff --git a/src/Game.cpp b/src/Game.cpp index 8b59365..ac2b130 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -64,7 +64,7 @@ void Game::initBoard(){ void Game::updateBoard(){ for(int x=0; x < boardWidth; x++){ for(int y=0; y < boardHeight; y++){ - if(Game::bombCheck() == 0){ + if(Game::bombCheck(x, y) == 0){ tileMap[x][y] = 1; } } @@ -157,40 +157,36 @@ void Game::displayBoard() { } } -int Game::bombCheck(){ - int bombsAround[boardWidth][boardHeight]; +int Game::bombCheck(int x, int y){ + int bombsAround = 0; - for(int x=0; x < boardWidth; x++){ - for(int y=0; y < boardHeight; y++){ - if(tileMap[x][y] == 1){ - if(bombMap[x-1][y-1] == true){ - bombsAround[x][y]++; - } - if(bombMap[x][y-1] == true){ - bombsAround[x][y]++; - } - if(bombMap[x+1][y-1] == true){ - bombsAround[x][y]++; - } - if(bombMap[x-1][y] == true){ - bombsAround[x][y]++; - } - if(bombMap[x+1][y] == true){ - bombsAround[x][y]++; - } - if(bombMap[x-1][y+1] == true){ - bombsAround[x][y]++; - } - if(bombMap[x][y+1] == true){ - bombsAround[x][y]++; - } - if(bombMap[x+1][y+1] == true){ - bombsAround[x][y]++; - } - return bombsAround[x][y]; - } + if(tileMap[x][y] == 1){ + if(bombMap[x-1][y-1] == true){ + bombsAround++; + } + if(bombMap[x][y-1] == true){ + bombsAround++; + } + if(bombMap[x+1][y-1] == true){ + bombsAround++; + } + if(bombMap[x-1][y] == true){ + bombsAround++; + } + if(bombMap[x+1][y] == true){ + bombsAround++; + } + if(bombMap[x-1][y+1] == true){ + bombsAround++; + } + if(bombMap[x][y+1] == true){ + bombsAround++; + } + if(bombMap[x+1][y+1] == true){ + bombsAround++; } } + return bombsAround; } void Game::input(){ diff --git a/src/Game.hpp b/src/Game.hpp index 88fc36b..cc6217a 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -21,7 +21,7 @@ public: void initBoard(); void updateBoard(); void displayBoard(); - int bombCheck(); + int bombCheck(int x, int y); void input(); }; |
