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.cpp91
1 files changed, 88 insertions, 3 deletions
diff --git a/src/Controllers/SFMLController/SFMLController.cpp b/src/Controllers/SFMLController/SFMLController.cpp
index cd676a9..e037c0b 100644
--- a/src/Controllers/SFMLController/SFMLController.cpp
+++ b/src/Controllers/SFMLController/SFMLController.cpp
@@ -5,8 +5,7 @@
-SFMLController::SFMLController() : m_MainWindow(800,800, "2P11"){
-
+SFMLController::SFMLController() : m_game(), m_MainWindow(800,800, "2P11"){
}
@@ -19,6 +18,9 @@ SFMLController::~SFMLController(){
void SFMLController::run(){
+ kbdh::Direction keyPress;
+
+ m_game.popRandomNumber();
while(m_MainWindow.isOpen()){
@@ -28,11 +30,94 @@ void SFMLController::run(){
// é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.
+ }
}
+
+
m_MainWindow.clearBG();
- m_MainWindow.drawCells();
+ //m_game.swipe(kbdh::Direction::Left);
+ m_MainWindow.drawGrid(m_game.getGrid());
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;
+}