summaryrefslogtreecommitdiff
path: root/src/Controllers/SFMLController/SFMLController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controllers/SFMLController/SFMLController.cpp')
-rw-r--r--src/Controllers/SFMLController/SFMLController.cpp82
1 files changed, 16 insertions, 66 deletions
diff --git a/src/Controllers/SFMLController/SFMLController.cpp b/src/Controllers/SFMLController/SFMLController.cpp
index 1c21753..5a5960f 100644
--- a/src/Controllers/SFMLController/SFMLController.cpp
+++ b/src/Controllers/SFMLController/SFMLController.cpp
@@ -3,27 +3,32 @@
+//==================== Constructor and Destructor ====================
-
+//Constructor
SFMLController::SFMLController() : m_game(), m_MainWindow(600,800, "2P11"){
}
-
+//Destructor
SFMLController::~SFMLController(){
}
-
-
+//Run controller
void SFMLController::run(){
+ //Init keypress
kbdh::Direction keyPress;
+ //First pop
m_game.popRandomNumber();
- while(m_MainWindow.isOpen()){
+ //Start game
+ while(m_MainWindow.isOpen()){
+
+ //Check event
sf::Event event;
while (m_MainWindow.pollEvent(event))
{
@@ -54,71 +59,16 @@ void SFMLController::run(){
}
+ //Clear window
m_MainWindow.clearBG();
- //m_game.swipe(kbdh::Direction::Left);
- std::vector<std::vector<int> > aaa=m_game.getGrid();
- m_MainWindow.drawGame(aaa,m_game.isOver(), m_game.getStats());
- m_MainWindow.display();
- //keyPress=this->waitArrowKeyPress();
- m_game.swipe(keyPress);
- }
-
-
-}
+ //Draw the game
+ m_MainWindow.drawGame(m_game.getGrid(),m_game.isOver(), m_game.getStats());
-//Wait for keypress and return the keyPress.
-kbdh::Direction SFMLController::waitArrowKeyPress()
-{
- //Initialise keyPress
- kbdh::Direction keyPress;
-
- //White space to remove arrows print by the terminal
- std::string spaces=" ";
+ //Display the changements
+ m_MainWindow.display();
- //Wait for keypress
- while(1){
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
- {
- keyPress=kbdh::Left;
- while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
- {
- //Wait for release and try to remove arrow printed characters
- std::cout << "\r" << spaces;
- }
- break;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- {
- keyPress=kbdh::Right;
- while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- {
- //Wait for release and try to remove arrow printed characters
- std::cout << "\r" << spaces;
- }
- break;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- {
- keyPress=kbdh::Up;
- while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- {
- //Wait for release and try to remove arrow printed characters
- std::cout << "\r" << spaces;
- }
- break;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
- {
- keyPress=kbdh::Down;
- while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
- {
- //Wait for release and try to remove arrow printed characters
- std::cout << "\r" << spaces;
- }
- break;
- }
}
- return keyPress;
+
}