package visualiser.gameController.Keys; import java.util.HashMap; import java.util.Map; /** * Factory for creating Keys, these could be predefined in the future. */ public class KeyFactory { /** * Retrieve command given key */ private Map keyState; /** * Singleton instance to enforce consistent key state */ private static KeyFactory theFactory = new KeyFactory(); /** * Singleton constructor for key state, set up initial state of each action. */ private KeyFactory() { this.keyState = new HashMap<>(); keyState.put("Z", new ZoomInKey("Zoom In")); keyState.put("X", new ZoomOutKey("Zoom Out")); keyState.put("SPACE", new VMGKey("VMG")); keyState.put("SHIFT", new SailsToggleKey("Toggle Sails")); keyState.put("ENTER", new TackGybeKey("Tack/Gybe")); keyState.put("UP", new UpWindKey("Upwind")); keyState.put("DOWN", new DownWindKey("Downwind")); } /** * Get singleton instance of KeyFactory to interact with key state * @return automatically constructed KeyFactory */ public static KeyFactory getFactory() { return theFactory; } /** * Get the Control Key in charge of a key press * @param key key pressed (String value of KeyCode) * @return the Control Key behaviour of the key pressed. */ public ControlKey getKey(String key){ return keyState.get(key); } }