diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-05-04 17:12:57 +0200 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-05-04 17:12:57 +0200 |
| commit | f7610d669bcf3986827a905fc4bc03946be0b0c6 (patch) | |
| tree | 43a12abdca9b13a805955d847b86d31d6e02aa66 | |
| parent | e72ce203657c6fdcbb3dab840672c6dba2df7894 (diff) | |
Clean some other things
| -rw-r--r-- | src/Controllers/SFMLController/SFMLController.cpp | 82 | ||||
| -rw-r--r-- | src/Controllers/SFMLController/SFMLController.hpp | 14 | ||||
| -rw-r--r-- | src/Model/Grid.cpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 6 |
4 files changed, 30 insertions, 74 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 diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index 64d8048..e510bed 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -347,7 +347,7 @@ std::vector<int> Grid::getCol(int col){ return colVect; } - +//Retrieve the grid for the view std::vector<std::vector<int> > Grid::getGrid(){ return m_grid; } diff --git a/src/main.cpp b/src/main.cpp index 45c029c..165c067 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,8 +21,10 @@ int main() srand(time(NULL)); //Init controller - //SFMLController controller; - ConsoleController controller; + SFMLController controller; + + //ConsoleController controller; + //Run the game controller.run(); |
