package com.haru.input;

import static com.haru.input.Key.DOWN;
import static com.haru.input.Key.LEFT;
import static com.haru.input.Key.RIGHT;
import static com.haru.input.Key.R_LEFT;
import static com.haru.input.Key.R_RIGHT;
import static com.haru.input.Key.UP;

import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;


/**
 * Keyとintの対応表.
 *
 * 使用例
<pre>
	KeyBind keyBind = new KeyBind(VK_S, VK_X, VK_Z, VK_C, VK_SPACE, VK_B);

	private void check(int code) {

		Key k = b1.get(code);
		if (k != null ) {
			switch(k) {
			case UP:
				System.out.println("上");
				break;
			case DOWN:
				System.out.println("下");
				break;
			case LEFT:
				System.out.println("左");
				break;
			case RIGHT:
				System.out.println("右");
				break;
			}
		}
	}
</pre>
 */

public class KeyBind {
	Map<Key, Integer> map;

	public KeyBind(int up, int down, int left, int right, int r_right, int r_left) {
		map = new EnumMap<Key, Integer>(Key.class);
		map.put(UP, up);
		map.put(DOWN, down);
		map.put(LEFT, left);
		map.put(RIGHT, right);
		map.put(R_RIGHT, r_right);
		map.put(R_LEFT, r_left);

	}

	public Key get(int code) {

		if (!map.containsValue(code))
			return null;


		for (Entry<Key,Integer> entry : map.entrySet()) {

			// 最初に一致したKeyを返す
			if (entry.getValue() == code) {
				return entry.getKey();
			}
		}

		System.out.println("codeが見つからない！！！");
		return null;
	}
}



