diff options
Diffstat (limited to 'src/Game.cpp')
| -rw-r--r-- | src/Game.cpp | 28 |
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; |
