diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-05-02 23:05:44 +0200 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-05-02 23:05:44 +0200 |
| commit | 710cc4001f65ac2fee39e25d79f43a01b9e12512 (patch) | |
| tree | 2e78e337b0c7d0f79bd68205badc1630326118ed /src/Controllers | |
| parent | fec126f0d2d48310109f85c3647b10ce393db5e8 (diff) | |
| parent | 1d09a0fd3ae35ccf51a3b5f929f77a8c8850712c (diff) | |
First stable fusionning
Diffstat (limited to 'src/Controllers')
| -rw-r--r-- | src/Controllers/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/Controllers/ConsoleController/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/Controllers/ConsoleController/ConsoleController.cpp | 97 | ||||
| -rw-r--r-- | src/Controllers/ConsoleController/ConsoleController.hpp | 26 |
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 |
