summaryrefslogtreecommitdiff
path: root/src/Game.cpp
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/Game.cpp
parent59c0c07568d607e69c437853c472379741f7aa98 (diff)
Fixes game winmentv1.0.0
Diffstat (limited to 'src/Game.cpp')
-rw-r--r--src/Game.cpp28
1 files changed, 24 insertions, 4 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;