diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-19 09:47:28 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-19 09:47:28 +0100 |
| commit | 6b5d1f3b4d66eb624683c886930d0fa7f46fe7b9 (patch) | |
| tree | 745105fae07823652cc4dc768996e2b08d0bf4d9 /src/se | |
| parent | cf665801d957eb7a7a67291d2972af5f649d57da (diff) | |
| download | tdde30-6b5d1f3b4d66eb624683c886930d0fa7f46fe7b9.tar.gz | |
move constructor and some formatting
Diffstat (limited to 'src/se')
| -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 +} |
