first version of the controller
This commit is contained in:
parent
a3b805ee7b
commit
71ebf1235e
4 changed files with 97 additions and 6 deletions
48
src/CTController/CTConsole.cpp
Normal file
48
src/CTController/CTConsole.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "CTConsole.hpp"
|
||||
|
||||
CTConsole::CTConsole()
|
||||
{
|
||||
m_game = new Game();
|
||||
}
|
||||
|
||||
CTConsole::~CTConsole()
|
||||
{
|
||||
delete m_game;
|
||||
}
|
||||
|
||||
void CTConsole::play()
|
||||
{
|
||||
while (!m_game->isOver())
|
||||
{
|
||||
m_game->showGrid();
|
||||
char moveChoice = ' ';
|
||||
|
||||
std::cin >> moveChoice;
|
||||
|
||||
switch (moveChoice)
|
||||
{
|
||||
case 'z':
|
||||
std::cout << "up" << std::endl;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
std::cout << "down" << std::endl;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
std::cout << "left" << std::endl;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
std::cout << "right" << std::endl;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
m_game->pop();
|
||||
}
|
||||
}
|
26
src/CTController/CTConsole.hpp
Normal file
26
src/CTController/CTConsole.hpp
Normal file
|
@ -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 "../Model/Game.hpp"
|
||||
|
||||
class CTConsole
|
||||
{
|
||||
private:
|
||||
Game * m_game;
|
||||
|
||||
public:
|
||||
CTConsole();
|
||||
~CTConsole();
|
||||
|
||||
void play();
|
||||
};
|
||||
|
||||
#endif
|
12
src/Model/ModelConstants.hpp
Normal file
12
src/Model/ModelConstants.hpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef DEF_MODELCONSTANTS
|
||||
#define DEF_MODELCONSTANTS
|
||||
|
||||
/* ModelConstants.hpp
|
||||
* Constains constants and enums used in the whole model
|
||||
* Creators : krilius, manzerbredes
|
||||
* Date : 29/04/2015 */
|
||||
|
||||
enum Direction { UP, DOWN, LEFT, RIGHT };
|
||||
typedef enum Direction Direction;
|
||||
|
||||
#endif
|
17
src/main.cpp
17
src/main.cpp
|
@ -1,13 +1,18 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
#include "Model/Grid.hpp"
|
||||
#include "CTController/CTConsole.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Grid * grid = new Grid(4);
|
||||
|
||||
grid->afficher();
|
||||
|
||||
return 0;
|
||||
srand(time(NULL));
|
||||
|
||||
CTConsole * controller = new CTConsole();
|
||||
|
||||
controller->play();
|
||||
|
||||
delete controller;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue