summaryrefslogtreecommitdiff
path: root/src/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'src/Controllers')
-rw-r--r--src/Controllers/CMakeLists.txt1
-rw-r--r--src/Controllers/ConsoleController/CMakeLists.txt3
-rw-r--r--src/Controllers/ConsoleController/ConsoleController.cpp97
-rw-r--r--src/Controllers/ConsoleController/ConsoleController.hpp26
4 files changed, 127 insertions, 0 deletions
diff --git a/src/Controllers/CMakeLists.txt b/src/Controllers/CMakeLists.txt
new file mode 100644
index 0000000..7ebeb19
--- /dev/null
+++ b/src/Controllers/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(./ConsoleController/)
diff --git a/src/Controllers/ConsoleController/CMakeLists.txt b/src/Controllers/ConsoleController/CMakeLists.txt
new file mode 100644
index 0000000..d42803f
--- /dev/null
+++ b/src/Controllers/ConsoleController/CMakeLists.txt
@@ -0,0 +1,3 @@
+#Make Model lib
+add_library(ConsoleController ./ConsoleController.cpp)
+target_link_libraries(ConsoleController Model)
diff --git a/src/Controllers/ConsoleController/ConsoleController.cpp b/src/Controllers/ConsoleController/ConsoleController.cpp
new file mode 100644
index 0000000..d91e807
--- /dev/null
+++ b/src/Controllers/ConsoleController/ConsoleController.cpp
@@ -0,0 +1,97 @@
+#include "./ConsoleController.hpp"
+#include <SFML/Window/Keyboard.hpp>
+#include "../../Helpers/Keyboard.hpp"
+
+ConsoleController::ConsoleController()
+{
+}
+
+ConsoleController::~ConsoleController()
+{
+}
+
+void ConsoleController::run()
+{
+
+ //Init keyPress
+ kbdh::Direction keyPress;
+
+ //Intruction msg
+ std::cout << "Use arrows to play !" << std::endl;
+
+ //Pop a random number on the grid
+ m_game.popRandomNumber();
+
+ //First cout grid
+ m_game.coutGrid();
+
+
+ //Start game
+ while (!m_game.isOver())
+ {
+ //Get key press
+ keyPress=this->waitArrowKeyPress();
+
+ //Apply move
+ m_game.swipe(keyPress);
+
+ //Pop a random number on the grid
+ m_game.popRandomNumber();
+
+ //Cout grid
+ m_game.coutGrid();
+
+ }
+ m_game.coutGrid();
+}
+
+
+
+kbdh::Direction ConsoleController::waitArrowKeyPress()
+{
+ //Initialise keyPress
+ kbdh::Direction keyPress;
+
+ //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
+ }
+ break;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
+ {
+ keyPress=kbdh::Right;
+ while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
+ {
+ //Wait for release
+ }
+ break;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
+ {
+ keyPress=kbdh::Up;
+ while(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
+ {
+ //Wait for release
+ }
+ break;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
+ {
+ // la touche "flèche gauche" est enfoncée : on bouge le personnage
+ keyPress=kbdh::Down;
+ while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
+ {
+ //Wait for release
+ }
+ break;
+ }
+ }
+
+ return keyPress;
+}
diff --git a/src/Controllers/ConsoleController/ConsoleController.hpp b/src/Controllers/ConsoleController/ConsoleController.hpp
new file mode 100644
index 0000000..8d73f79
--- /dev/null
+++ b/src/Controllers/ConsoleController/ConsoleController.hpp
@@ -0,0 +1,26 @@
+#ifndef DEF_CTCONSOLE
+#define DEF_CTCONSOLE
+
+/* CTConsole.hpp
+ * Defines the class CTConsole
+ * CTConsole is a controller which displays a game in a terminal
+ * Creators : krilius, manzerbredes
+ * Date : 29/04/2915 */
+
+#include <iostream>
+#include "../../Helpers/Keyboard.hpp"
+#include "../../Model/Game.hpp"
+
+class ConsoleController
+{
+ private:
+
+ Game m_game;
+ kbdh::Direction waitArrowKeyPress();
+ public:
+ ConsoleController();
+ ~ConsoleController();
+ void run();
+};
+
+#endif