diff options
Diffstat (limited to 'src/Controllers')
| -rw-r--r-- | src/Controllers/SFMLController/SFMLController.cpp | 82 | ||||
| -rw-r--r-- | src/Controllers/SFMLController/SFMLController.hpp | 14 |
2 files changed, 25 insertions, 71 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; + } diff --git a/src/Controllers/SFMLController/SFMLController.hpp b/src/Controllers/SFMLController/SFMLController.hpp index 0bb0eea..0847268 100644 --- a/src/Controllers/SFMLController/SFMLController.hpp +++ b/src/Controllers/SFMLController/SFMLController.hpp @@ -1,26 +1,30 @@ - +#ifndef __SFMLCONTROLLER__ +#define __SFMLCONTROLLER__ #include <iostream> #include <string> + #include <SFML/Window.hpp> +#include <SFML/Window/Keyboard.hpp> + #include "../../View/MainWindow.hpp" #include "../../Model/Game.hpp" #include "../../Helpers/Keyboard.hpp" -#include <SFML/Window/Keyboard.hpp> + + class SFMLController{ private: MainWindow m_MainWindow; Game m_game; - - public: SFMLController(); ~SFMLController(); - kbdh::Direction waitArrowKeyPress(); void run(); }; + +#endif |
