summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Game.cpp19
-rw-r--r--src/Game.hpp3
-rw-r--r--src/main.cpp16
3 files changed, 31 insertions, 7 deletions
diff --git a/src/Game.cpp b/src/Game.cpp
index 7e54371..3e7384b 100644
--- a/src/Game.cpp
+++ b/src/Game.cpp
@@ -103,6 +103,12 @@ int Game::editDiff(){
*/
void Game::displayBoard() {
+ #ifdef _WIN32
+ system("cls");
+ #else
+ system("clear");
+ #endif
+
for (int i = 0; i < boardHeight; i++) {
for (int j = 0; j < boardWidth; j++) {
if (tileMap[i][j] == 0) {
@@ -130,3 +136,16 @@ void Game::displayBoard() {
putchar('\n');
}
}
+
+void Game::input(){
+ std::string input;
+
+ std::cout << "game>";
+ std::cin >> input;
+
+ if(input == "q"){
+ inGame = false;
+ } else {
+ std::cout << "Unknown command '" << input << "'.\n";
+ }
+}
diff --git a/src/Game.hpp b/src/Game.hpp
index 767ab94..882bb02 100644
--- a/src/Game.hpp
+++ b/src/Game.hpp
@@ -15,10 +15,13 @@ private:
int mines;
public:
+ bool inGame;
+
int editDiff();
void initDiff(int diff);
void initBoard();
void displayBoard();
+ void input();
};
#endif
diff --git a/src/main.cpp b/src/main.cpp
index ef12c62..d4dab15 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,7 +4,7 @@ using namespace std;
int main(){
Game game;
- bool inGame = false;
+ game.inGame = false;
int choice;
cout << "Welcome to minesweeper 0.1.0\n";
@@ -19,21 +19,23 @@ int main(){
if(choice == 1){
game.initDiff(0);
- inGame = true;
+ game.inGame = true;
} else if(choice == 2){
game.initDiff(1);
- inGame = true;
+ game.inGame = true;
} else if(choice == 3){
game.initDiff(2);
- inGame = true;
+ game.inGame = true;
} else if(choice == 4){
game.editDiff();
- inGame = true;
+ game.inGame = true;
}
- while(inGame){
- game.initBoard();
+ game.initBoard();
+
+ while(game.inGame){
game.displayBoard();
+ game.input();
}
return 0;