diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 329f303..6fb4a14 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -12,6 +12,19 @@ public class Controller { private boolean inputHandled; private GameState gameState; + private void initializeInputHandling() + { + final int CONDITION = JComponent.WHEN_IN_FOCUSED_WINDOW; + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("W"), "move up"); + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("A"), "move left"); + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("S"), "move down"); + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("D"), "move right"); + + gameView.getActionMap().put("move up", new MoveAction(Snake.SnakeDirection.UP)); + gameView.getActionMap().put("move left", new MoveAction(Snake.SnakeDirection.LEFT)); + gameView.getActionMap().put("move down", new MoveAction(Snake.SnakeDirection.DOWN)); + gameView.getActionMap().put("move right", new MoveAction(Snake.SnakeDirection.RIGHT)); + } private class MoveAction extends AbstractAction {