From 2e9b97faf5b5c123da612e4b82c914dcd79bc959 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 11:04:14 +0100 Subject: Simplified bombCheck --- src/Game.cpp | 60 ++++++++++++++++++++++++++++-------------------------------- src/Game.hpp | 2 +- 2 files changed, 29 insertions(+), 33 deletions(-) (limited to 'src') 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(); }; -- cgit v1.2.3