From 5f871f7a4c95201764b1d6725ad338b04b8040cf Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 10:40:49 +0100 Subject: Added bombCheck method in Game --- src/Game.cpp | 35 +++++++++++++++++++++++++++++++++++ src/Game.hpp | 1 + 2 files changed, 36 insertions(+) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index a703913..82c5eb7 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -147,6 +147,41 @@ void Game::displayBoard() { } } +void Game::bombCheck(){ + for(int x=0; x < boardWidth; x++){ + for(int y=0; y < boardHeight; y++){ + if(tileMap[x][y] == 1){ + int bombsAround[boardWidth][boardHeight]; + + 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]++; + } + } + } + } +} + void Game::input(){ std::string input; diff --git a/src/Game.hpp b/src/Game.hpp index 61a788e..e828780 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -20,6 +20,7 @@ public: void initDiff(int diff); void initBoard(); void displayBoard(); + void bombCheck(); void input(); }; -- cgit v1.2.3 From 3d9a91fb44c8ae43779e80e12a4a2da87cc9b3b9 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 10:57:17 +0100 Subject: Starting to handle board update --- src/.Game.cpp.swp | Bin 16384 -> 0 bytes src/Game.cpp | 21 ++++++++++++++++----- src/Game.hpp | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) delete mode 100644 src/.Game.cpp.swp (limited to 'src') diff --git a/src/.Game.cpp.swp b/src/.Game.cpp.swp deleted file mode 100644 index d32da3a..0000000 Binary files a/src/.Game.cpp.swp and /dev/null differ diff --git a/src/Game.cpp b/src/Game.cpp index 82c5eb7..8b59365 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -54,8 +54,18 @@ void Game::initBoard(){ tileMap[i][j] = 0; // DEBUG: seeing bombs - if(bombMap[i][j] == true){ - tileMap[i][j] = 11; + // if(bombMap[i][j] == true){ + // tileMap[i][j] = 11; + // } + } + } +} + +void Game::updateBoard(){ + for(int x=0; x < boardWidth; x++){ + for(int y=0; y < boardHeight; y++){ + if(Game::bombCheck() == 0){ + tileMap[x][y] = 1; } } } @@ -147,12 +157,12 @@ void Game::displayBoard() { } } -void Game::bombCheck(){ +int Game::bombCheck(){ + int bombsAround[boardWidth][boardHeight]; + for(int x=0; x < boardWidth; x++){ for(int y=0; y < boardHeight; y++){ if(tileMap[x][y] == 1){ - int bombsAround[boardWidth][boardHeight]; - if(bombMap[x-1][y-1] == true){ bombsAround[x][y]++; } @@ -177,6 +187,7 @@ void Game::bombCheck(){ if(bombMap[x+1][y+1] == true){ bombsAround[x][y]++; } + return bombsAround[x][y]; } } } diff --git a/src/Game.hpp b/src/Game.hpp index e828780..88fc36b 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -19,8 +19,9 @@ public: int editDiff(); void initDiff(int diff); void initBoard(); + void updateBoard(); void displayBoard(); - void bombCheck(); + int bombCheck(); void input(); }; -- cgit v1.2.3 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 From 394661ef8a982708cde152322bebea648fd72745 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 11:07:37 +0100 Subject: Finished bomb checking --- src/Game.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index ac2b130..3d7aa86 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -66,6 +66,22 @@ void Game::updateBoard(){ for(int y=0; y < boardHeight; y++){ if(Game::bombCheck(x, y) == 0){ tileMap[x][y] = 1; + } else if(Game::bombCheck(x, y) == 1){ + tileMap[x][y] = 2; + } else if(Game::bombCheck(x, y) == 2){ + tileMap[x][y] = 3; + } else if(Game::bombCheck(x, y) == 3){ + tileMap[x][y] = 4; + } else if(Game::bombCheck(x, y) == 4){ + tileMap[x][y] = 5; + } else if(Game::bombCheck(x, y) == 5){ + tileMap[x][y] = 6; + } else if(Game::bombCheck(x, y) == 6){ + tileMap[x][y] = 7; + } else if(Game::bombCheck(x, y) == 7){ + tileMap[x][y] = 8; + } else if(Game::bombCheck(x, y) == 8){ + tileMap[x][y] = 9; } } } -- cgit v1.2.3 From 211dfea719540a78c57f970555979f1a25c960ed Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 12:12:00 +0100 Subject: Fixing game --- src/Game.cpp | 25 ++++++++++++++++--------- src/Game.hpp | 1 + src/main.cpp | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 3d7aa86..d26373c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -52,6 +52,7 @@ void Game::initBoard(){ for(int i=0; i < boardHeight; i++){ for(int j=0; j < boardWidth; j++){ tileMap[i][j] = 0; + revealed[i][j] = false; // DEBUG: seeing bombs // if(bombMap[i][j] == true){ @@ -64,23 +65,29 @@ void Game::initBoard(){ void Game::updateBoard(){ for(int x=0; x < boardWidth; x++){ for(int y=0; y < boardHeight; y++){ - if(Game::bombCheck(x, y) == 0){ + if(revealed[x][y] == false){ + tileMap[x][y] = 0; + } else { tileMap[x][y] = 1; - } else if(Game::bombCheck(x, y) == 1){ + } + + if(Game::bombCheck(x, y) == 0 && revealed[x][y] == true){ + tileMap[x][y] = 1; + } else if(Game::bombCheck(x, y) == 1 && revealed[x][y] == true){ tileMap[x][y] = 2; - } else if(Game::bombCheck(x, y) == 2){ + } else if(Game::bombCheck(x, y) == 2 && revealed[x][y] == true){ tileMap[x][y] = 3; - } else if(Game::bombCheck(x, y) == 3){ + } else if(Game::bombCheck(x, y) == 3 && revealed[x][y] == true){ tileMap[x][y] = 4; - } else if(Game::bombCheck(x, y) == 4){ + } else if(Game::bombCheck(x, y) == 4 && revealed[x][y] == true){ tileMap[x][y] = 5; - } else if(Game::bombCheck(x, y) == 5){ + } else if(Game::bombCheck(x, y) == 5 && revealed[x][y] == true){ tileMap[x][y] = 6; - } else if(Game::bombCheck(x, y) == 6){ + } else if(Game::bombCheck(x, y) == 6 && revealed[x][y] == true){ tileMap[x][y] = 7; - } else if(Game::bombCheck(x, y) == 7){ + } else if(Game::bombCheck(x, y) == 7 && revealed[x][y] == true){ tileMap[x][y] = 8; - } else if(Game::bombCheck(x, y) == 8){ + } else if(Game::bombCheck(x, y) == 8 && revealed[x][y] == true){ tileMap[x][y] = 9; } } diff --git a/src/Game.hpp b/src/Game.hpp index cc6217a..207202f 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -10,6 +10,7 @@ private: bool bombMap[MAX_H][MAX_W]; int tileMap[MAX_H][MAX_W]; + bool revealed[MAX_H][MAX_W]; int mines; diff --git a/src/main.cpp b/src/main.cpp index d4dab15..3cb5551 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,6 +34,7 @@ int main(){ game.initBoard(); while(game.inGame){ + game.updateBoard(); game.displayBoard(); game.input(); } -- cgit v1.2.3 From 455f9e494d43b73a2ebee8d2f23b0ebe4fc255b0 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 12:16:50 +0100 Subject: Added reveal map --- src/Game.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index d26373c..80bff12 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -72,7 +72,14 @@ void Game::updateBoard(){ } if(Game::bombCheck(x, y) == 0 && revealed[x][y] == true){ - tileMap[x][y] = 1; + revealed[x-1][y+1] = true; + revealed[x][y+1] = true; + revealed[x+1][y+1] = true; + revealed[x-1][y] = true; + revealed[x+1][y] = true; + revealed[x-1][y-1] = true; + revealed[x][y-1] = true; + revealed[x+1][y-1] = true; } else if(Game::bombCheck(x, y) == 1 && revealed[x][y] == true){ tileMap[x][y] = 2; } else if(Game::bombCheck(x, y) == 2 && revealed[x][y] == true){ -- cgit v1.2.3 From 53c7572acc0b7d11af77edd1d8934371a348220b Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 12:28:15 +0100 Subject: Fixes --- src/Game.cpp | 8 +------- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 80bff12..6a75758 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -57,7 +57,7 @@ void Game::initBoard(){ // DEBUG: seeing bombs // if(bombMap[i][j] == true){ // tileMap[i][j] = 11; - // } + //} } } } @@ -65,12 +65,6 @@ void Game::initBoard(){ void Game::updateBoard(){ for(int x=0; x < boardWidth; x++){ for(int y=0; y < boardHeight; y++){ - if(revealed[x][y] == false){ - tileMap[x][y] = 0; - } else { - tileMap[x][y] = 1; - } - if(Game::bombCheck(x, y) == 0 && revealed[x][y] == true){ revealed[x-1][y+1] = true; revealed[x][y+1] = true; diff --git a/src/main.cpp b/src/main.cpp index 3cb5551..6dd0102 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,9 +34,9 @@ int main(){ game.initBoard(); while(game.inGame){ - game.updateBoard(); game.displayBoard(); game.input(); + game.updateBoard(); } return 0; -- cgit v1.2.3 From a0339e27d1d8f07cd7b8b687269b7db7d918cccf Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 13:37:05 +0100 Subject: Fixed game logic --- src/Game.cpp | 190 +++++++++++++++++++++-------------------------------------- src/main.cpp | 1 + 2 files changed, 68 insertions(+), 123 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 6a75758..f230a04 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -29,68 +29,33 @@ 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] = 0; + for(int y=0; y < boardHeight; y++){ + for(int x=0; x < boardWidth; x++){ + bombMap[y][x] = false; + revealed[y][x] = false; + tileMap[y][x] = 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; - } - } - } + int placed = 0; + while(placed < mines){ + int x = rand() % boardWidth; + int y = rand() % boardHeight; - // initializing tile map for display - - for(int i=0; i < boardHeight; i++){ - for(int j=0; j < boardWidth; j++){ - tileMap[i][j] = 0; - revealed[i][j] = false; - - // DEBUG: seeing bombs - // if(bombMap[i][j] == true){ - // tileMap[i][j] = 11; - //} + if(!bombMap[y][x]){ + bombMap[y][x] = true; + placed++; } } } void Game::updateBoard(){ - for(int x=0; x < boardWidth; x++){ - for(int y=0; y < boardHeight; y++){ - if(Game::bombCheck(x, y) == 0 && revealed[x][y] == true){ - revealed[x-1][y+1] = true; - revealed[x][y+1] = true; - revealed[x+1][y+1] = true; - revealed[x-1][y] = true; - revealed[x+1][y] = true; - revealed[x-1][y-1] = true; - revealed[x][y-1] = true; - revealed[x+1][y-1] = true; - } else if(Game::bombCheck(x, y) == 1 && revealed[x][y] == true){ - tileMap[x][y] = 2; - } else if(Game::bombCheck(x, y) == 2 && revealed[x][y] == true){ - tileMap[x][y] = 3; - } else if(Game::bombCheck(x, y) == 3 && revealed[x][y] == true){ - tileMap[x][y] = 4; - } else if(Game::bombCheck(x, y) == 4 && revealed[x][y] == true){ - tileMap[x][y] = 5; - } else if(Game::bombCheck(x, y) == 5 && revealed[x][y] == true){ - tileMap[x][y] = 6; - } else if(Game::bombCheck(x, y) == 6 && revealed[x][y] == true){ - tileMap[x][y] = 7; - } else if(Game::bombCheck(x, y) == 7 && revealed[x][y] == true){ - tileMap[x][y] = 8; - } else if(Game::bombCheck(x, y) == 8 && revealed[x][y] == true){ - tileMap[x][y] = 9; - } + for(int y=0; y < boardHeight; y++){ + for(int x=0; x < boardWidth; x++){ + if(!revealed[y][x]) continue; + + int bombs = bombCheck(x, y); + tileMap[y][x] = bombs == 0 ? 1 : bombs + 1; } } } @@ -149,90 +114,69 @@ void Game::displayBoard() { system("clear"); #endif - for(int i=0; i < boardHeight; i++){ - 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'); - } else if(tileMap[i][j] == 10){ - putchar('X'); - } else if(tileMap[i][j] == 11){ - putchar('B'); - } + for(int y=0; y < boardHeight; y++){ + for(int x; x < boardWidth; x++){ + if(tileMap[y][x] == 0) putchar('#'); + else if(tileMap[y][x] == 1) putchar('.'); + else putchar('0' + tileMap[y][x] - 1); } putchar('\n'); } } int Game::bombCheck(int x, int y){ - int bombsAround = 0; + int count = 0; - 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++; + for(int dy = -1; dy <= 1; dy++){ + for(int dx = -1; dx <= 1; dx++){ + if(dx == 0 && dy == 0) continue; + + int nx = x + dx; + int ny = y + dy; + + if(nx >= 0 && nx < boardWidth && ny >= 0 && ny < boardHeight && bombMap[ny][nx]){ + count++; + } } } - return bombsAround; + return count; } void Game::input(){ - std::string input; + std::string cmd; + std::cout << "game> "; + std::cin >> cmd; - std::cout << "game>"; - std::cin >> input; + if(cmd == "q"){ + inGame = false; + return; + } - if(input == "q"){ - inGame = false; + int x, y; + std::cin >> x >> y; - } else if(input == "d"){ - int x, y; - std::cout << "Enter column and row where to dig: "; - std::cin >> x >> y; - tileMap[x][y] = 1; - } else if(input == "f"){ - int x, y; - std::cout << "Enter column and row where to place flag: "; - std::cin >> x >> y; - tileMap[x][y] = 10; - } else { - std::cout << "Unknown command '" << input << "'.\n"; + if(x < 0 || x >= boardWidth || y < 0 || y >= boardHeight) return; + if(cmd == "d"){ + if(bombMap[y][x]){ + std::cout << "BOOM! Game over\n"; + inGame = false; + return; + } + + if(!revealed[y][x]){ + revealed[y][x] = true; + if(bombCheck(x, y) == 0){ + for(int dy = -1; dy <= 1; dy++){ + for(int dx = -1; dx <= 1; dx++){ + int nx = x + dx; + int ny = y + dy; + + if(nx >= 0 && nx < boardWidth && ny >= 0 && ny < boardHeight && !revealed[ny][nx]){ + revealed[ny][nx] = true; + } + } + } + } + } } } diff --git a/src/main.cpp b/src/main.cpp index 6dd0102..9f70dcd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ int main(){ game.inGame = true; } + srand(time(nullptr)); game.initBoard(); while(game.inGame){ -- cgit v1.2.3 From b4a18c82230f6c081ec0a7b5d6b8d64e256db4d4 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 13:38:28 +0100 Subject: patch --- minesweeper | Bin 0 -> 53552 bytes src/Game.cpp | 2 +- src/Game.o | Bin 0 -> 15200 bytes src/main.o | Bin 0 -> 7336 bytes 4 files changed, 1 insertion(+), 1 deletion(-) create mode 100755 minesweeper create mode 100644 src/Game.o create mode 100644 src/main.o (limited to 'src') diff --git a/minesweeper b/minesweeper new file mode 100755 index 0000000..466b37c Binary files /dev/null and b/minesweeper differ diff --git a/src/Game.cpp b/src/Game.cpp index f230a04..87686c0 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -115,7 +115,7 @@ void Game::displayBoard() { #endif for(int y=0; y < boardHeight; y++){ - for(int x; x < boardWidth; x++){ + for(int x = 0; x < boardWidth; x++){ if(tileMap[y][x] == 0) putchar('#'); else if(tileMap[y][x] == 1) putchar('.'); else putchar('0' + tileMap[y][x] - 1); diff --git a/src/Game.o b/src/Game.o new file mode 100644 index 0000000..261e5ac Binary files /dev/null and b/src/Game.o differ diff --git a/src/main.o b/src/main.o new file mode 100644 index 0000000..0751ff9 Binary files /dev/null and b/src/main.o differ -- cgit v1.2.3 From 5db654635e6b4990d86df324b011c7411996c521 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 13:40:04 +0100 Subject: Cleaned builds --- minesweeper | Bin 53552 -> 0 bytes src/Game.o | Bin 15200 -> 0 bytes src/main.o | Bin 7336 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100755 minesweeper delete mode 100644 src/Game.o delete mode 100644 src/main.o (limited to 'src') diff --git a/minesweeper b/minesweeper deleted file mode 100755 index 466b37c..0000000 Binary files a/minesweeper and /dev/null differ diff --git a/src/Game.o b/src/Game.o deleted file mode 100644 index 261e5ac..0000000 Binary files a/src/Game.o and /dev/null differ diff --git a/src/main.o b/src/main.o deleted file mode 100644 index 0751ff9..0000000 Binary files a/src/main.o and /dev/null differ -- cgit v1.2.3 From 4ba41733aa9b1f4c94c9370d1e754787ee16c911 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 14:33:40 +0100 Subject: Fixed input --- src/Game.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 87686c0..3ed709f 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -147,6 +147,10 @@ void Game::input(){ std::cout << "game> "; std::cin >> cmd; + if(std::cin.fail()){ + std::cout << "Input failed." << std::endl; + } + if(cmd == "q"){ inGame = false; return; -- cgit v1.2.3 From b39ee318ac6cd9d7d1eeeb7ed9df6dfa4aeec924 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 14:36:28 +0100 Subject: Handling return for failed input --- src/Game.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 3ed709f..327e179 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -149,6 +149,7 @@ void Game::input(){ if(std::cin.fail()){ std::cout << "Input failed." << std::endl; + return; } if(cmd == "q"){ -- cgit v1.2.3 From cd14289702fd22ed65536dccd61fd9569198b644 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 14:52:35 +0100 Subject: Revoked placing flags feature --- minesweeper | Bin 0 -> 53712 bytes src/Game.cpp | 6 ++++++ src/Game.hpp | 1 + src/Game.o | Bin 0 -> 15680 bytes src/main.o | Bin 0 -> 7336 bytes 5 files changed, 7 insertions(+) create mode 100755 minesweeper create mode 100644 src/Game.o create mode 100644 src/main.o (limited to 'src') diff --git a/minesweeper b/minesweeper new file mode 100755 index 0000000..4d37823 Binary files /dev/null and b/minesweeper differ diff --git a/src/Game.cpp b/src/Game.cpp index 327e179..e08ab24 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -34,6 +34,7 @@ void Game::initBoard(){ bombMap[y][x] = false; revealed[y][x] = false; tileMap[y][x] = 0; + flag[y][x] = false; } } @@ -53,6 +54,8 @@ void Game::updateBoard(){ for(int y=0; y < boardHeight; y++){ for(int x=0; x < boardWidth; x++){ if(!revealed[y][x]) continue; + if(!flag[y][x]) continue; + else tileMap[y][x] = 10; int bombs = bombCheck(x, y); tileMap[y][x] = bombs == 0 ? 1 : bombs + 1; @@ -118,6 +121,7 @@ void Game::displayBoard() { for(int x = 0; x < boardWidth; x++){ if(tileMap[y][x] == 0) putchar('#'); else if(tileMap[y][x] == 1) putchar('.'); + else if(tileMap[y][x] == 10) putchar('F'); else putchar('0' + tileMap[y][x] - 1); } putchar('\n'); @@ -184,4 +188,6 @@ void Game::input(){ } } } + + if(cmd == "f") } diff --git a/src/Game.hpp b/src/Game.hpp index 207202f..ca3cb33 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -11,6 +11,7 @@ private: bool bombMap[MAX_H][MAX_W]; int tileMap[MAX_H][MAX_W]; bool revealed[MAX_H][MAX_W]; + bool flag[MAX_H][MAX_W]; int mines; diff --git a/src/Game.o b/src/Game.o new file mode 100644 index 0000000..813d1bb Binary files /dev/null and b/src/Game.o differ diff --git a/src/main.o b/src/main.o new file mode 100644 index 0000000..0751ff9 Binary files /dev/null and b/src/main.o differ -- cgit v1.2.3 From 0b47e6d00261d20d27ff10f5ee3d3e5d1660c766 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 14:54:28 +0100 Subject: Handling flag placinf --- src/Game.cpp | 4 +++- src/Game.o | Bin 15680 -> 0 bytes 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 src/Game.o (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index e08ab24..01bff24 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -189,5 +189,7 @@ void Game::input(){ } } - if(cmd == "f") + if(cmd == "f"){ + flag[y][x] = true; + } } diff --git a/src/Game.o b/src/Game.o deleted file mode 100644 index 813d1bb..0000000 Binary files a/src/Game.o and /dev/null differ -- cgit v1.2.3 From f9f1a41a404d9b6d0da20d0d61eebb752ddb5896 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 15:03:18 +0100 Subject: removed flag feature; now starting from v0.2.0 --- minesweeper | Bin 53712 -> 53728 bytes src/Game.cpp | 12 ++++++------ src/Game.o | Bin 0 -> 15688 bytes src/main.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 src/Game.o (limited to 'src') diff --git a/minesweeper b/minesweeper index 4d37823..07b9dd0 100755 Binary files a/minesweeper and b/minesweeper differ diff --git a/src/Game.cpp b/src/Game.cpp index 01bff24..c545530 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -34,7 +34,7 @@ void Game::initBoard(){ bombMap[y][x] = false; revealed[y][x] = false; tileMap[y][x] = 0; - flag[y][x] = false; + // flag[y][x] = false; } } @@ -54,7 +54,7 @@ void Game::updateBoard(){ for(int y=0; y < boardHeight; y++){ for(int x=0; x < boardWidth; x++){ if(!revealed[y][x]) continue; - if(!flag[y][x]) continue; + // if(!flag[y][x]) continue; else tileMap[y][x] = 10; int bombs = bombCheck(x, y); @@ -121,7 +121,7 @@ void Game::displayBoard() { for(int x = 0; x < boardWidth; x++){ if(tileMap[y][x] == 0) putchar('#'); else if(tileMap[y][x] == 1) putchar('.'); - else if(tileMap[y][x] == 10) putchar('F'); + // else if(tileMap[y][x] == 10) putchar('F'); else putchar('0' + tileMap[y][x] - 1); } putchar('\n'); @@ -189,7 +189,7 @@ void Game::input(){ } } - if(cmd == "f"){ - flag[y][x] = true; - } + //if(cmd == "f"){ + // flag[y][x] = true; + //} } diff --git a/src/Game.o b/src/Game.o new file mode 100644 index 0000000..a9ed709 Binary files /dev/null and b/src/Game.o differ diff --git a/src/main.cpp b/src/main.cpp index 9f70dcd..afea063 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,7 @@ int main(){ game.inGame = false; int choice; - cout << "Welcome to minesweeper 0.1.0\n"; + cout << "Welcome to minesweeper v0.2.0\n"; cout << "\n"; cout << "Select difficulty:\n" "1. Easy\n" -- cgit v1.2.3 From 236f7163826edf5a6f521c382fd6f21e460c81d2 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Tue, 3 Feb 2026 15:06:35 +0100 Subject: Cleaned bud files; Updated from README to README.html --- README | 5 ----- README.html | 8 ++++++++ minesweeper | Bin 53728 -> 0 bytes src/Game.o | Bin 15688 -> 0 bytes src/main.o | Bin 7336 -> 0 bytes 5 files changed, 8 insertions(+), 5 deletions(-) delete mode 100644 README create mode 100644 README.html delete mode 100755 minesweeper delete mode 100644 src/Game.o delete mode 100644 src/main.o (limited to 'src') diff --git a/README b/README deleted file mode 100644 index 1da92d7..0000000 --- a/README +++ /dev/null @@ -1,5 +0,0 @@ -# minesweeper - -A reimplementation of minesweeper game in C++ in terminal. - -Written in ![https://www.vim.org/](assets/vim_on_fire.gif) and VS Codium. diff --git a/README.html b/README.html new file mode 100644 index 0000000..e6fb572 --- /dev/null +++ b/README.html @@ -0,0 +1,8 @@ +

minesweeper

+ +

A reimplementation of minesweeper +game in C++ in terminal.

+ +

Written in + +and VS Codium.

diff --git a/minesweeper b/minesweeper deleted file mode 100755 index 07b9dd0..0000000 Binary files a/minesweeper and /dev/null differ diff --git a/src/Game.o b/src/Game.o deleted file mode 100644 index a9ed709..0000000 Binary files a/src/Game.o and /dev/null differ diff --git a/src/main.o b/src/main.o deleted file mode 100644 index 0751ff9..0000000 Binary files a/src/main.o and /dev/null differ -- cgit v1.2.3 From 087f11a6f89559030fd9aa88bb7a4663211c9184 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Fri, 6 Feb 2026 17:40:20 +0100 Subject: Removed unused whitespaces --- src/Game.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index c545530..07c1519 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -12,7 +12,7 @@ void Game::initDiff(int diff){ boardHeight = 9; mines = 9; break; - case 1: + case 1: boardWidth = 16; boardHeight = 16; mines = 12; @@ -163,7 +163,7 @@ void Game::input(){ int x, y; std::cin >> x >> y; - + if(x < 0 || x >= boardWidth || y < 0 || y >= boardHeight) return; if(cmd == "d"){ if(bombMap[y][x]){ @@ -192,4 +192,4 @@ void Game::input(){ //if(cmd == "f"){ // flag[y][x] = true; //} -} +} -- cgit v1.2.3 From 520f59a571330d183db421b81cb841771d0e0a82 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Fri, 6 Feb 2026 18:26:50 +0100 Subject: Removed unused case --- src/Game.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 07c1519..ad8eed0 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -22,9 +22,6 @@ void Game::initDiff(int diff){ boardHeight = 16; mines = 16; break; - case 3: - std::cout << "Editing game parameters\n"; - break; } } -- cgit v1.2.3 From c6a425785ae0b6ef22a4881bc139dd1b36c7d1c5 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Sun, 8 Feb 2026 11:53:17 +0100 Subject: Fixing flag feature --- src/Game.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index ad8eed0..f5d71e1 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -51,7 +51,7 @@ void Game::updateBoard(){ for(int y=0; y < boardHeight; y++){ for(int x=0; x < boardWidth; x++){ if(!revealed[y][x]) continue; - // if(!flag[y][x]) continue; + if(flag[y][x]) continue; else tileMap[y][x] = 10; int bombs = bombCheck(x, y); @@ -118,7 +118,7 @@ void Game::displayBoard() { for(int x = 0; x < boardWidth; x++){ if(tileMap[y][x] == 0) putchar('#'); else if(tileMap[y][x] == 1) putchar('.'); - // else if(tileMap[y][x] == 10) putchar('F'); + else if(tileMap[y][x] == 10) putchar('F'); else putchar('0' + tileMap[y][x] - 1); } putchar('\n'); @@ -186,7 +186,11 @@ void Game::input(){ } } - //if(cmd == "f"){ - // flag[y][x] = true; - //} + if(cmd == "f"){ + if(revealed[y][x]){ + std::cout << "You can't place flag here.\n"; + } else { + flag[y][x] = true; + } + } } -- cgit v1.2.3 From f44d54293ccde8c53a74b098167d56698378d425 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Sun, 8 Feb 2026 13:32:41 +0100 Subject: Patching flag display --- src/Game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index f5d71e1..2b2d184 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -51,7 +51,7 @@ void Game::updateBoard(){ for(int y=0; y < boardHeight; y++){ for(int x=0; x < boardWidth; x++){ if(!revealed[y][x]) continue; - if(flag[y][x]) continue; + if(flag[y][x]) tileMap[y][x] = 10; else tileMap[y][x] = 10; int bombs = bombCheck(x, y); -- cgit v1.2.3 From ec009e93d6e78eb3e6a609deb8b969a855597115 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Sun, 8 Feb 2026 16:40:57 +0100 Subject: Properly exiting game on failed input --- src/Game.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index 2b2d184..f3d92f6 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -150,6 +150,7 @@ void Game::input(){ if(std::cin.fail()){ std::cout << "Input failed." << std::endl; + inGame = false; return; } -- cgit v1.2.3 From 80553898f80858e6e66613c889ed9f19327a1cf6 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Sun, 8 Feb 2026 17:26:56 +0100 Subject: Attempts to fix flags displaying --- src/Game.cpp | 21 ++++++++++----------- src/Game.hpp | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Game.cpp b/src/Game.cpp index f3d92f6..d98c5e9 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -29,9 +29,9 @@ void Game::initBoard(){ for(int y=0; y < boardHeight; y++){ for(int x=0; x < boardWidth; x++){ bombMap[y][x] = false; - revealed[y][x] = false; + revealedMap[y][x] = false; tileMap[y][x] = 0; - // flag[y][x] = false; + flagMap[y][x] = false; } } @@ -50,9 +50,8 @@ void Game::initBoard(){ void Game::updateBoard(){ for(int y=0; y < boardHeight; y++){ for(int x=0; x < boardWidth; x++){ - if(!revealed[y][x]) continue; - if(flag[y][x]) tileMap[y][x] = 10; - else tileMap[y][x] = 10; + if(!revealedMap[y][x]) continue; + else if(flagMap[y][x] == true) continue; int bombs = bombCheck(x, y); tileMap[y][x] = bombs == 0 ? 1 : bombs + 1; @@ -170,16 +169,16 @@ void Game::input(){ return; } - if(!revealed[y][x]){ - revealed[y][x] = true; + if(!revealedMap[y][x]){ + revealedMap[y][x] = true; if(bombCheck(x, y) == 0){ for(int dy = -1; dy <= 1; dy++){ for(int dx = -1; dx <= 1; dx++){ int nx = x + dx; int ny = y + dy; - if(nx >= 0 && nx < boardWidth && ny >= 0 && ny < boardHeight && !revealed[ny][nx]){ - revealed[ny][nx] = true; + if(nx >= 0 && nx < boardWidth && ny >= 0 && ny < boardHeight && !revealedMap[ny][nx]){ + revealedMap[ny][nx] = true; } } } @@ -188,10 +187,10 @@ void Game::input(){ } if(cmd == "f"){ - if(revealed[y][x]){ + if(revealedMap[y][x]){ std::cout << "You can't place flag here.\n"; } else { - flag[y][x] = true; + flagMap[y][x] = true; } } } diff --git a/src/Game.hpp b/src/Game.hpp index ca3cb33..599259f 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -10,8 +10,8 @@ private: bool bombMap[MAX_H][MAX_W]; int tileMap[MAX_H][MAX_W]; - bool revealed[MAX_H][MAX_W]; - bool flag[MAX_H][MAX_W]; + bool revealedMap[MAX_H][MAX_W]; + bool flagMap[MAX_H][MAX_W]; int mines; -- cgit v1.2.3