#include "manual.h"

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 user who pressed an illegal key.
		punish();
	}

	//Arrive here if the user pressed no key, or pressed an illegal key.
	*dx = *dy = 0;
}