From f7610d669bcf3986827a905fc4bc03946be0b0c6 Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Mon, 4 May 2015 17:12:57 +0200 Subject: [PATCH] Clean some other things --- .../SFMLController/SFMLController.cpp | 82 ++++--------------- .../SFMLController/SFMLController.hpp | 14 ++-- src/Model/Grid.cpp | 2 +- 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(); + + + //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 > aaa=m_game.getGrid(); - m_MainWindow.drawGame(aaa,m_game.isOver(), m_game.getStats()); + + //Draw the game + m_MainWindow.drawGame(m_game.getGrid(),m_game.isOver(), m_game.getStats()); + + //Display the changements m_MainWindow.display(); - //keyPress=this->waitArrowKeyPress(); - m_game.swipe(keyPress); } } - -//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=" "; - - //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 #include + #include +#include + #include "../../View/MainWindow.hpp" #include "../../Model/Game.hpp" #include "../../Helpers/Keyboard.hpp" -#include + + 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 Grid::getCol(int col){ return colVect; } - +//Retrieve the grid for the view std::vector > 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();