diff options
| -rw-r--r-- | src/se/liu/gusso230/tetris/BoardToTextConverter.java | 3 | ||||
| -rw-r--r-- | src/se/liu/gusso230/tetris/TetrisComponent.java | 38 |
2 files changed, 20 insertions, 21 deletions
diff --git a/src/se/liu/gusso230/tetris/BoardToTextConverter.java b/src/se/liu/gusso230/tetris/BoardToTextConverter.java index 33d8c3b..399303c 100644 --- a/src/se/liu/gusso230/tetris/BoardToTextConverter.java +++ b/src/se/liu/gusso230/tetris/BoardToTextConverter.java @@ -1,8 +1,7 @@ package se.liu.gusso230.tetris; public class BoardToTextConverter { - public BoardToTextConverter() { - } + public BoardToTextConverter() {} private char fromSquareType(SquareType squareType) { switch (squareType) { diff --git a/src/se/liu/gusso230/tetris/TetrisComponent.java b/src/se/liu/gusso230/tetris/TetrisComponent.java index e9c14f0..f358e7a 100644 --- a/src/se/liu/gusso230/tetris/TetrisComponent.java +++ b/src/se/liu/gusso230/tetris/TetrisComponent.java @@ -12,6 +12,24 @@ public class TetrisComponent extends JComponent implements BoardListener { private Board board; + public TetrisComponent(final Board board) { + this.board = board; + + this.getInputMap().put(KeyStroke.getKeyStroke('a'), "moveLeft"); + this.getInputMap().put(KeyStroke.getKeyStroke('d'), "moveRight"); + this.getInputMap().put(KeyStroke.getKeyStroke('q'), "rotateLeft"); + this.getInputMap().put(KeyStroke.getKeyStroke('e'), "rotateRight"); + this.getInputMap().put(KeyStroke.getKeyStroke("LEFT"), "moveLeft"); + this.getInputMap().put(KeyStroke.getKeyStroke("RIGHT"), "moveRight"); + this.getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "rotateLeft"); + this.getInputMap().put(KeyStroke.getKeyStroke("UP"), "rotateRight"); + + this.getActionMap().put("moveLeft", new MoveAction(Direction.LEFT)); + this.getActionMap().put("moveRight", new MoveAction(Direction.RIGHT)); + this.getActionMap().put("rotateLeft", new RotateAction(Direction.LEFT)); + this.getActionMap().put("rotateRight", new RotateAction(Direction.RIGHT)); + } + private class MoveAction extends AbstractAction { private Direction dir; private MoveAction(Direction dir) { @@ -34,24 +52,6 @@ public class TetrisComponent extends JComponent implements BoardListener { } } - public TetrisComponent(final Board board) { - this.board = board; - - this.getInputMap().put(KeyStroke.getKeyStroke('a'), "moveLeft"); - this.getInputMap().put(KeyStroke.getKeyStroke('d'), "moveRight"); - this.getInputMap().put(KeyStroke.getKeyStroke('q'), "rotateLeft"); - this.getInputMap().put(KeyStroke.getKeyStroke('e'), "rotateRight"); - this.getInputMap().put(KeyStroke.getKeyStroke("LEFT"), "moveLeft"); - this.getInputMap().put(KeyStroke.getKeyStroke("RIGHT"), "moveRight"); - this.getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "rotateLeft"); - this.getInputMap().put(KeyStroke.getKeyStroke("UP"), "rotateRight"); - - this.getActionMap().put("moveLeft", new MoveAction(Direction.LEFT)); - this.getActionMap().put("moveRight", new MoveAction(Direction.RIGHT)); - this.getActionMap().put("rotateLeft", new RotateAction(Direction.LEFT)); - this.getActionMap().put("rotateRight", new RotateAction(Direction.RIGHT)); - } - @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Graphics2D g2d = (Graphics2D) g; @@ -88,4 +88,4 @@ public class TetrisComponent extends JComponent implements BoardListener { map.put(SquareType.L, Color.PINK); return map; } -}
\ No newline at end of file +} |
