From 353846e64a2f810e6e527837a6e236ea31704ebb Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Sun, 1 Feb 2026 12:28:06 +0100 Subject: Updated Game.cpp and README.md --- README.md | 2 -- src/Game.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index be88dbe..8031120 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ # minesweeper A reimplementation of minesweeper game in C++ in terminal. - -Full documentation can be found in `docs` directory and [in GitHub deployed site](https://dawidg81.github.io/minesweeper/). \ No newline at end of file diff --git a/src/Game.cpp b/src/Game.cpp index 988c467..ad29029 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -29,12 +29,26 @@ void Game::initDiff(int diff) { } void Game::initBoard() { + // Bomb map (boolean): 0 or false is no bomb, 1 or true is bomb; + // clearing bomb map for (int i = 0; i < boardHeight; i++) { for (int j = 0; j < boardWidth; j++) { - bombMap[i][j] = rand() % 2; + for(int k = 0; k < mines; k++){ + bombMap[i][j] = 0; + } } } + // initializing bomb map + for (int i = 0; i < boardHeight; i++) { + for (int j = 0; j < boardWidth; j++) { + for(int k = 0; k < mines; k++){ + bombMap[i][j] = rand() % 2; + } + } + } + + // initializing tile map for display for (int i = 0; i < boardHeight; i++) { for (int j = 0; j < boardWidth; j++) { tileMap[i][j] = 0; @@ -55,10 +69,45 @@ int Game::editDiff(){ return 0; } +/* Tile map: + +0 - unrevealed tile +1 - revealed tile +2 - revealed tile with 1 bomb around +3 - revealed tile with 2 bomb around +4 - revealed tile with 3 bomb around +5 - revealed tile with 4 bomb around +6 - revealed tile with 5 bomb around +7 - revealed tile with 6 bomb around +8 - revealed tile with 7 bomb around +9 - revealed tile with 8 bomb around + +*/ void Game::displayBoard() { for (int i = 0; i < boardHeight; i++) { - for (int j = 0; j < boardWidth; j++) - putchar(tileMap[i][j]); + for (int j = 0; j < boardWidth; j++) { + if (tileMap[i][j] == 0) { + putchar('#'); + } else if (tileMap[i][j] == 1) { + putchar('.'); + } else if (tileMap[i][j] == 2) { + putchar('1'); + } else if (tileMap[i][j] == 3) { + putchar('2'); + } else if (tileMap[i][j] == 4) { + putchar('3'); + } else if (tileMap[i][j] == 5) { + putchar('4'); + } else if (tileMap[i][j] == 6) { + putchar('5'); + } else if (tileMap[i][j] == 7) { + putchar('6'); + } else if (tileMap[i][j] == 8) { + putchar('7'); + } else if (tileMap[i][j] == 9) { + putchar('8'); + } + } putchar('\n'); } } \ No newline at end of file -- cgit v1.2.3