#include #include "wolf.h" using namespace std; void wolf::decide(int *dx, int *dy) const { struct keystroke { char c; int dx; //horizontal motion int dy; //vertical motion }; static const keystroke a[] { {'h', -1, 0}, //left {'j', 0, 1}, //down {'k', 0, -1}, //up {'l', 1, 0} //right }; if (const char k {key()}) { //If a key was pressed, for (const auto& stroke: a) { //search for it. if (k == stroke.c) { *dx = stroke.dx; *dy = stroke.dy; return; } } } *dx = 0; *dy = 0; }