Add arrow support for ConsoleController (using SFML Keyboard.hpp)

This commit is contained in:
manzerbredes 2015-05-01 11:59:40 +02:00
parent 6392288967
commit 03b57472fc
2 changed files with 64 additions and 10 deletions

View file

@ -1,4 +1,6 @@
#include "./ConsoleController.hpp"
#include <SFML/Window/Keyboard.hpp>
#include "../../Model/ModelConstants.hpp"
ConsoleController::ConsoleController()
{
@ -12,35 +14,88 @@ ConsoleController::~ConsoleController()
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())
{
m_game->showGrid();
char moveChoice = ' ';
//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;
}
}
std::cin >> moveChoice;
switch (moveChoice)
//Check for keypress
switch (keyPress)
{
case 'z':
case UP:
std::cout << "up" << std::endl;
break;
case 's':
case DOWN:
std::cout << "down" << std::endl;
break;
case 'q':
case LEFT:
std::cout << "left" << std::endl;
break;
case 'd':
case RIGHT:
std::cout << "right" << std::endl;
break;
default:
default:
break;
}
//Show the Grid
m_game->showGrid();
std::cout << std::endl;
//Pop new number
m_game->pop();
}
}

View file

@ -29,7 +29,6 @@ Grid::~Grid()
}
}
void Grid::show()
{
std::cout << "_________________" << std::endl;