From 57eb7d9e23c67547cf797a45875c96c554b74275 Mon Sep 17 00:00:00 2001 From: dawidg81 Date: Mon, 9 Feb 2026 15:15:40 +0100 Subject: Fixes game winment --- src/Game.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/Game.cpp') 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; -- cgit v1.2.3