summaryrefslogtreecommitdiff
path: root/src/Game.cpp
diff options
context:
space:
mode:
authordawidg81 <dawidgorski.m@gmail.com>2026-02-09 14:47:41 +0100
committerdawidg81 <dawidgorski.m@gmail.com>2026-02-09 14:47:41 +0100
commit59c0c07568d607e69c437853c472379741f7aa98 (patch)
tree7908e2980d916415f59781a844b7435413393f1a /src/Game.cpp
parentc72d094dec277fe99089422c1e7fd990e5e086da (diff)
Made tiles revealing recursivev0.4.0
Diffstat (limited to 'src/Game.cpp')
-rw-r--r--src/Game.cpp28
1 files changed, 8 insertions, 20 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);
}
}