summaryrefslogtreecommitdiff
path: root/src/Controller/ConsoleController/ConsoleController.cpp
blob: 81e16f4c801e8a170d65b3970d58e55389184604 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "./ConsoleController.hpp"
#include <SFML/Window/Keyboard.hpp>
#include "../../Model/ModelConstants.hpp"

ConsoleController::ConsoleController()
{
	m_game = new Game();
}

ConsoleController::~ConsoleController()
{
	delete m_game;
}

void ConsoleController::play()
{

	std::cout << "Use arrows to play !" << std::endl;

	//Init keyPress
	Direction keyPress;

	//Display the first grid
	m_game->showGrid();

	//Start game
	while (!m_game->isOver())
	{
		//Wait for keypress
		while(1){
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
			{
				keyPress=LEFT;
				while(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
				{
					//Wait for release
				}
				break;
			}
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
			{
				keyPress=RIGHT;
				while(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
				{
					//Wait for release
				}
				break;
			}
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
			{
				keyPress=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=DOWN;
				while(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
				{
					//Wait for release
				}
				break;
			}
		}


		//Check for keypress
		switch (keyPress)
		{
			case UP:
				std::cout << "up" << std::endl;
				break;

			case DOWN:
				std::cout << "down" << std::endl;
				break;

			case LEFT:
				std::cout << "left" << std::endl;
				break;
			case RIGHT:
				std::cout << "right" << std::endl;
				break;

			default:
				break;
		}

		//Show the Grid
		m_game->showGrid();
		std::cout << std::endl;

		//Pop new number
		m_game->pop();

	}
}