diff options
| author | dawidg81 <dawidgorski.m@gmail.com> | 2026-02-09 14:47:41 +0100 |
|---|---|---|
| committer | dawidg81 <dawidgorski.m@gmail.com> | 2026-02-09 14:47:41 +0100 |
| commit | 59c0c07568d607e69c437853c472379741f7aa98 (patch) | |
| tree | 7908e2980d916415f59781a844b7435413393f1a /src | |
| parent | c72d094dec277fe99089422c1e7fd990e5e086da (diff) | |
Made tiles revealing recursivev0.4.0
Diffstat (limited to 'src')
| -rw-r--r-- | src/Game.cpp | 28 | ||||
| -rw-r--r-- | src/Game.hpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 1 |
3 files changed, 10 insertions, 21 deletions
diff --git a/src/Game.cpp b/src/Game.cpp index 18e09cd..4e44888 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -3,6 +3,7 @@ #include <cstdlib> #include <cstdio> #include <iostream> +#include <ostream> #include <string> void Game::initDiff(int diff) @@ -171,7 +172,7 @@ int Game::bombCheck(int x, int y) return count; } -void Game::revealTile(int x, int y){ +void Game::revealTile(int y, int x){ revealedMap[y][x] = true; if(bombCheck(x, y) == 0) @@ -185,6 +186,7 @@ void Game::revealTile(int x, int y){ if(nx >= 0 && nx < boardWidth && ny >= 0 && ny < boardHeight && !revealedMap[ny][nx]){ revealedMap[ny][nx] = true; + revealTile(ny, nx); } } } @@ -198,6 +200,8 @@ void Game::input() std::cout << "game> "; std::cin >> cmd; + // std::cout << cmd; + if(std::cin.fail()) { std::cout << "Input failed." << std::endl; @@ -206,14 +210,14 @@ void Game::input() return; } - if(cmd == "q"){ + if(cmd == "q") + { inGame = false; return; } int x, y; std::cin >> x >> y; - std::cout << x << y; if(x < 0 || x >= boardWidth || y < 0 || y >= boardHeight) return; @@ -234,23 +238,7 @@ void Game::input() if(!revealedMap[y][x]) { - 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; - } - } - } - } + revealTile(y, x); } } diff --git a/src/Game.hpp b/src/Game.hpp index 15eadd3..749f75d 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -30,7 +30,7 @@ public: int bombCheck(int x, int y); - void revealTile(int x, int y); + void revealTile(int y, int x); void input(); }; diff --git a/src/main.cpp b/src/main.cpp index 21ceb01..97117a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ int main(){ game.displayBoard(); game.input(); game.updateBoard(); + // cout << game.inGame; } return 0; |
