From c4f70660d01d7d25a7f7a1e78d6e72097ca82e2e Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Mon, 9 Feb 2026 19:00:56 +0100 Subject: Added board numbering, added unflagging, fixed message display --- .gitignore | 1 + minesweeper.exe | Bin 158662 -> 0 bytes src/Game.cpp | 23 +++++++++++++++++++++-- src/Game.hpp | 4 ++-- src/main.cpp | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) delete mode 100644 minesweeper.exe diff --git a/.gitignore b/.gitignore index 931307c..8363075 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o +*.exe minesweeper diff --git a/minesweeper.exe b/minesweeper.exe deleted file mode 100644 index c4cde59..0000000 Binary files a/minesweeper.exe and /dev/null differ diff --git a/src/Game.cpp b/src/Game.cpp index e81ccd3..c9c53dd 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -62,11 +62,17 @@ void Game::updateBoard() { for(int x=0; x < boardWidth; x++) { - if(flagMap[y][x] == true) + if (flagMap[y][x] == true) { tileMap[y][x] = 10; continue; } + else if (!flagMap[y][x] && !revealedMap[y][x]) + { + tileMap[y][x] = 0; + continue; + } + else if(!revealedMap[y][x]) continue; int bombs = bombCheck(x, y); @@ -134,10 +140,18 @@ void Game::displayBoard() system("clear"); #endif - std::cout << msg; + std::cout << msg << "\n "; + + for (int i = 0; i < boardHeight; i++) { + std::cout << i; + } + + std::cout << "\n\n"; for(int y=0; y < boardHeight; y++) { + std::cout << y << " "; + for(int x = 0; x < boardWidth; x++) { if(tileMap[y][x] == 0) putchar('#'); @@ -148,6 +162,7 @@ void Game::displayBoard() putchar('\n'); } + putchar('\n'); } int Game::bombCheck(int x, int y) @@ -267,6 +282,10 @@ void Game::input() if(revealedMap[y][x]) { msg = "You can't place flag on revealed tile.\n"; + } + + if(flagMap[y][x]){ + flagMap[y][x] = false; } else { flagMap[y][x] = true; } diff --git a/src/Game.hpp b/src/Game.hpp index a723f5d..9b720a9 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -17,12 +17,12 @@ private: int mines; + std::string msg; + public: bool inGame; bool hasWon(); - std::string msg; - int editDiff(); void initDiff(int diff); void initBoard(); diff --git a/src/main.cpp b/src/main.cpp index 16a8b13..8bbb1d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,7 @@ int main(){ game.input(); game.updateBoard(); game.hasWon(); - cout << game.msg; + // cout << game.msg; // cout << game.inGame; } -- cgit v1.2.3