2P11/src/Controllers/SFMLController/SFMLController.cpp
2015-05-05 16:30:46 +02:00

73 lines
1.3 KiB
C++

#include "SFMLController.hpp"
//==================== 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))
{
// évènement "fermeture demandée" : on ferme la fenêtre
if (event.type == sf::Event::Closed)
m_MainWindow.close();
if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Up)
{
m_game.swipe(kbdh::Direction::Up);
}
if (event.key.code == sf::Keyboard::Down)
{
m_game.swipe(kbdh::Direction::Down);
// Do something when W is pressed...
}
if (event.key.code == sf::Keyboard::Left){
m_game.swipe(kbdh::Direction::Left);
}
if (event.key.code == sf::Keyboard::Right){
m_game.swipe(kbdh::Direction::Right);
}
// And so on.
}
}
//Clear window
m_MainWindow.clearBG();
//Draw the game
m_MainWindow.drawGame(m_game.getGrid(),m_game.isOver(), m_game.getStats());
//Display the changements
m_MainWindow.display();
}
}