Hello ! I have a problem and I could not find a answer. I need handle a whichever key form keyboard (in specific case) and i dont know how to do it.
Below is code in c++.
void SnakeGame::initializeDirectionMap(){
mapOfDirects[sf::Keyboard::Right] = std::shared_ptr<DirectConditions>(new GoRight);
mapOfDirects[sf::Keyboard::Left] = std::shared_ptr<DirectConditions>(new GoLeft);
mapOfDirects[sf::Keyboard::Up] = std::shared_ptr<DirectConditions>(new GoUp);
mapOfDirects[sf::Keyboard::Down] = std::shared_ptr<DirectConditions>(new GoDown);
mapOfDirects[sf::Keyboard::End] = std::shared_ptr<DirectConditions>(new Pause);
mapOfDirects[sf::Keyboard::AnyKey] = std::shared_ptr<DirectConditions>(new Exit); // i don't know how to do it
}
direction=event.key.code; // take key from keyboard
mapOfDirects[direction]->choosenDirection(*this); // choose which method have to execute by key from keyboard
Is even possible handle all keys in sf::Keyboard::Key type ? I mean I press A,B,F5, whatever and always mapOfDirect[sf::Keyboard::"AnyKey"] will be choosen that is what I need. ("AnyKey" means my leak of knowledge
I don't know what I have to put there instead of AnyKey)
If you know some tutorials or tips with events handle form keyboard which might help me solve this issue please share with me.
I would really appreciate help !