summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordawidg81 <dawidgorski.m@gmail.com>2026-02-09 15:15:40 +0100
committerdawidg81 <dawidgorski.m@gmail.com>2026-02-09 15:15:40 +0100
commit57eb7d9e23c67547cf797a45875c96c554b74275 (patch)
treeb467bee336807219d5265c23866a55c75fbca41e /src
parent59c0c07568d607e69c437853c472379741f7aa98 (diff)
Fixes game winmentv1.0.0
Diffstat (limited to 'src')
-rw-r--r--src/Game.cpp28
-rw-r--r--src/Game.hpp7
-rw-r--r--src/main.cpp2
3 files changed, 30 insertions, 7 deletions
diff --git a/src/Game.cpp b/src/Game.cpp
index 4e44888..e81ccd3 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -11,9 +11,9 @@ void Game::initDiff(int diff)
switch(diff)
{
case 0:
- boardWidth = 9;
- boardHeight = 9;
- mines = 9;
+ boardWidth = 4;
+ boardHeight = 4;
+ mines = 2;
break;
case 1:
boardWidth = 16;
@@ -181,10 +181,12 @@ void Game::revealTile(int y, int x){
{
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 && !revealedMap[ny][nx]){
+ if(nx >= 0 && nx < boardWidth && ny >= 0 && ny < boardHeight && !revealedMap[ny][nx])
+ {
revealedMap[ny][nx] = true;
revealTile(ny, nx);
}
@@ -193,6 +195,24 @@ void Game::revealTile(int y, int x){
}
}
+bool Game::hasWon(){
+ int revealedTiles = 0;
+
+ for(int y=0; y < boardHeight; y++)
+ {
+ for(int x = 0; x < boardWidth; x++)
+ {
+ if(revealedMap[y][x]) revealedTiles++;
+ }
+ }
+
+ if(boardWidth * boardHeight - mines == revealedTiles){
+ std::cout << "You have won!\n";
+ inGame = false;
+ }
+ return true;
+}
+
void Game::input()
{
std::string cmd;
diff --git a/src/Game.hpp b/src/Game.hpp
index 749f75d..a723f5d 100644
--- a/src/Game.hpp
+++ b/src/Game.hpp
@@ -10,17 +10,18 @@ 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];
bool flagMap[MAX_H][MAX_W];
int mines;
-
+
public:
bool inGame;
+ bool hasWon();
+
+ std::string msg;
int editDiff();
void initDiff(int diff);
diff --git a/src/main.cpp b/src/main.cpp
index 97117a4..16a8b13 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -42,6 +42,8 @@ int main(){
game.displayBoard();
game.input();
game.updateBoard();
+ game.hasWon();
+ cout << game.msg;
// cout << game.inGame;
}