#include "manual.h"
using namespace std;

void manual::decide(int *dx, int *dy) const
{
	struct keystroke {
		char c;
		int dx;		//horizontal difference
		int dy;		//vertical difference
	};

	static const keystroke a[] = {
		{'h',   -1,    0},		//left
		{'j',    0,    1},		//down
		{'k',    0,   -1},		//up
		{'l',    1,    0}		//right
	};
	static const size_t n = sizeof a / sizeof a[0];

	if (const char k = key()) {
		for (const keystroke *p = a; p < a + n; ++p) {
			if (k == p->c) {
				*dx = p->dx;
				*dy = p->dy;
				return;
			}
		}

		punish();   //Punish user who typed an illegal key.
	}

	//If the user hasn't pressed a valid key, don't move the wolf.
	*dx = *dy = 0;
}