summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordawidg81 <dawidgorski.m@gmail.com>2026-02-09 14:21:23 +0100
committerdawidg81 <dawidgorski.m@gmail.com>2026-02-09 14:21:23 +0100
commitc72d094dec277fe99089422c1e7fd990e5e086da (patch)
tree1ed237764f8894d7e8199ff5144a10f308a0a548
parent65e7a56dbd3e6c1f02d421a03bb9848f3257ae16 (diff)
Fixed flags displaying and revealement logic for flags handling
-rw-r--r--TODO.txt4
-rw-r--r--minesweeper.exebin123096 -> 124188 bytes
-rw-r--r--src/Game.cpp42
-rw-r--r--src/Game.hpp7
4 files changed, 47 insertions, 6 deletions
diff --git a/TODO.txt b/TODO.txt
index 09e841c..49b446d 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,3 +1,3 @@
Things to do:
-1. add flag placing
-2. make safe tiles reveal recursively \ No newline at end of file
+
+X - make safe tiles reveal recursively \ No newline at end of file
diff --git a/minesweeper.exe b/minesweeper.exe
index f9e7539..2dff3e0 100644
--- a/minesweeper.exe
+++ b/minesweeper.exe
Binary files differ
diff --git a/src/Game.cpp b/src/Game.cpp
index c46c9c4..18e09cd 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -61,8 +61,12 @@ void Game::updateBoard()
{
for(int x=0; x < boardWidth; x++)
{
- if(!revealedMap[y][x]) continue;
- else if(flagMap[y][x] == true) continue;
+ if(flagMap[y][x] == true)
+ {
+ tileMap[y][x] = 10;
+ continue;
+ }
+ else if(!revealedMap[y][x]) continue;
int bombs = bombCheck(x, y);
tileMap[y][x] = bombs == 0 ? 1 : bombs + 1;
@@ -129,6 +133,8 @@ void Game::displayBoard()
system("clear");
#endif
+ std::cout << msg;
+
for(int y=0; y < boardHeight; y++)
{
for(int x = 0; x < boardWidth; x++)
@@ -165,6 +171,26 @@ int Game::bombCheck(int x, int y)
return count;
}
+void Game::revealTile(int x, int y){
+ 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 && !revealedMap[ny][nx]){
+ revealedMap[ny][nx] = true;
+ }
+ }
+ }
+ }
+}
+
void Game::input()
{
std::string cmd;
@@ -187,13 +213,21 @@ void Game::input()
int x, y;
std::cin >> x >> y;
+ std::cout << x << y;
if(x < 0 || x >= boardWidth || y < 0 || y >= boardHeight) return;
+
if(cmd == "d")
{
+ if(flagMap[y][x])
+ {
+ msg = "You can't dig on flag.\n";
+ return;
+ }
+
if(bombMap[y][x])
{
- std::cout << "BOOM! Game over\n";
+ msg = "BOOM! Game over\n";
inGame = false;
return;
}
@@ -224,7 +258,7 @@ void Game::input()
{
if(revealedMap[y][x])
{
- std::cout << "You can't place flag here.\n";
+ msg = "You can't place flag on revealed tile.\n";
} else {
flagMap[y][x] = true;
}
diff --git a/src/Game.hpp b/src/Game.hpp
index 599259f..15eadd3 100644
--- a/src/Game.hpp
+++ b/src/Game.hpp
@@ -1,3 +1,5 @@
+#include <string>
+
#pragma once
class Game {
@@ -8,6 +10,8 @@ private:
int boardWidth;
int boardHeight;
+ std::string msg;
+
bool bombMap[MAX_H][MAX_W];
int tileMap[MAX_H][MAX_W];
bool revealedMap[MAX_H][MAX_W];
@@ -23,7 +27,10 @@ public:
void initBoard();
void updateBoard();
void displayBoard();
+
int bombCheck(int x, int y);
+
+ void revealTile(int x, int y);
void input();
};