summaryrefslogtreecommitdiff
path: root/src/Controllers/ConsoleController/ConsoleController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controllers/ConsoleController/ConsoleController.cpp')
-rw-r--r--src/Controllers/ConsoleController/ConsoleController.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/Controllers/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp
index d91e807..1bc9b84 100644
--- a/src/Controllers/ConsoleController/ConsoleController.cpp
+++ b/src/Controllers/ConsoleController/ConsoleController.cpp
@@ -2,14 +2,22 @@
#include <SFML/Window/Keyboard.hpp>
#include "../../Helpers/Keyboard.hpp"
+
+//==================== Constructor and Destructor ====================
+
+//Constructor
ConsoleController::ConsoleController()
{
}
+//Destructor
ConsoleController::~ConsoleController()
{
}
+//==================== Helpers ====================
+
+//Run the game.
void ConsoleController::run()
{
@@ -22,6 +30,9 @@ void ConsoleController::run()
//Pop a random number on the grid
m_game.popRandomNumber();
+ //First cout stats
+ this->coutStats();
+
//First cout grid
m_game.coutGrid();
@@ -33,20 +44,27 @@ void ConsoleController::run()
keyPress=this->waitArrowKeyPress();
//Apply move
- m_game.swipe(keyPress);
+ bool moveDone=m_game.swipe(keyPress);
- //Pop a random number on the grid
- m_game.popRandomNumber();
+ //Cout stats
+ this->coutStats();
//Cout grid
m_game.coutGrid();
}
+
+ //Last cout stats
+ this->coutStats();
+
+ //Last cout grid
m_game.coutGrid();
}
+
+//Wait for keypress and return the keyPress.
kbdh::Direction ConsoleController::waitArrowKeyPress()
{
//Initialise keyPress
@@ -59,7 +77,8 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
keyPress=kbdh::Left;
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
- //Wait for release
+ //Wait for release and try to remove arrow printed characters
+ std::cout << "\r" << " ";
}
break;
}
@@ -68,7 +87,8 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
keyPress=kbdh::Right;
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
- //Wait for release
+ //Wait for release and try to remove arrow printed characters
+ std::cout << "\r" << " ";
}
break;
}
@@ -77,17 +97,18 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
keyPress=kbdh::Up;
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
- //Wait for release
+ //Wait for release and try to remove arrow printed characters
+ std::cout << "\r" << " ";
}
break;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
- // la touche "flèche gauche" est enfoncée : on bouge le personnage
keyPress=kbdh::Down;
while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
- //Wait for release
+ //Wait for release and try to remove arrow printed characters
+ std::cout << "\r" << " ";
}
break;
}
@@ -95,3 +116,11 @@ kbdh::Direction ConsoleController::waitArrowKeyPress()
return keyPress;
}
+
+
+//Cout the stats of the game
+void ConsoleController::coutStats(){
+
+ std::cout << std::endl << "Score : " << m_game.getScore() << std::endl;
+ std::cout << "Nombre de coups : " << m_game.getNbMove() << std::endl;
+}