Add arrow support for ConsoleController (using SFML Keyboard.hpp)
This commit is contained in:
parent
6392288967
commit
03b57472fc
2 changed files with 64 additions and 10 deletions
|
@ -1,4 +1,6 @@
|
||||||
#include "./ConsoleController.hpp"
|
#include "./ConsoleController.hpp"
|
||||||
|
#include <SFML/Window/Keyboard.hpp>
|
||||||
|
#include "../../Model/ModelConstants.hpp"
|
||||||
|
|
||||||
ConsoleController::ConsoleController()
|
ConsoleController::ConsoleController()
|
||||||
{
|
{
|
||||||
|
@ -12,35 +14,88 @@ ConsoleController::~ConsoleController()
|
||||||
|
|
||||||
void ConsoleController::play()
|
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())
|
while (!m_game->isOver())
|
||||||
{
|
{
|
||||||
m_game->showGrid();
|
//Wait for keypress
|
||||||
char moveChoice = ' ';
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cin >> moveChoice;
|
|
||||||
|
|
||||||
switch (moveChoice)
|
//Check for keypress
|
||||||
|
switch (keyPress)
|
||||||
{
|
{
|
||||||
case 'z':
|
case UP:
|
||||||
std::cout << "up" << std::endl;
|
std::cout << "up" << std::endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case DOWN:
|
||||||
std::cout << "down" << std::endl;
|
std::cout << "down" << std::endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'q':
|
case LEFT:
|
||||||
std::cout << "left" << std::endl;
|
std::cout << "left" << std::endl;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case RIGHT:
|
||||||
std::cout << "right" << std::endl;
|
std::cout << "right" << std::endl;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Show the Grid
|
||||||
|
m_game->showGrid();
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
//Pop new number
|
||||||
m_game->pop();
|
m_game->pop();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ Grid::~Grid()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Grid::show()
|
void Grid::show()
|
||||||
{
|
{
|
||||||
std::cout << "_________________" << std::endl;
|
std::cout << "_________________" << std::endl;
|
||||||
|
|
Loading…
Add table
Reference in a new issue