summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--minesweeper.exebin155957 -> 158662 bytes
-rw-r--r--src/Game.cpp28
-rw-r--r--src/Game.hpp7
-rw-r--r--src/main.cpp2
4 files changed, 30 insertions, 7 deletions
diff --git a/minesweeper.exe b/minesweeper.exe
index f0e510d..c4cde59 100644
--- a/minesweeper.exe
+++ b/minesweeper.exe
Binary files differ
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;
diff --git a/src/Game.hpp b/src/Game.hpp
index 749f75d..a723f5d 100644
--- a/src/Game.hpp
+++ b/src/Game.hpp
@@ -10,17 +10,18 @@ private:
int boardWidth;
int boardHeight;
- std::string msg;
-
bool bombMap[MAX_H][MAX_W];
int tileMap[MAX_H][MAX_W];
bool revealedMap[MAX_H][MAX_W];
bool flagMap[MAX_H][MAX_W];
int mines;
-
+
public:
bool inGame;
+ bool hasWon();
+
+ std::string msg;
int editDiff();
void initDiff(int diff);
diff --git a/src/main.cpp b/src/main.cpp
index 97117a4..16a8b13 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -42,6 +42,8 @@ int main(){
game.displayBoard();
game.input();
game.updateBoard();
+ game.hasWon();
+ cout << game.msg;
// cout << game.inGame;
}