Browse Source

update

main
Justin Senn 2 years ago
parent
commit
50c194c333
  1. 13
      src/main/java/Snake/Controller.java

13
src/main/java/Snake/Controller.java

@ -12,6 +12,19 @@ public class Controller {
private boolean inputHandled; private boolean inputHandled;
private GameState gameState; 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 private class MoveAction extends AbstractAction
{ {

Loading…
Cancel
Save