From aa52b34d25e41758e51289a130ab893e7dbc550d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 4 Mar 2021 10:06:25 +0100 Subject: only check lines if placed falling piece --- src/se/liu/gusso230/tetris/Board.java | 13 ++++++++----- src/se/liu/gusso230/tetris/TetrisComponent.java | 13 +++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/se/liu/gusso230/tetris/Board.java b/src/se/liu/gusso230/tetris/Board.java index 7e11c7a..0ff4a84 100644 --- a/src/se/liu/gusso230/tetris/Board.java +++ b/src/se/liu/gusso230/tetris/Board.java @@ -81,7 +81,10 @@ public class Board { } else { moveFalling(); } - checkFullLines(); + if (falling == null) { + // only if falling was placed + checkFullLines(); + } updateFallHandler(); } } @@ -187,10 +190,6 @@ public class Board { notifyListeners(); } - public void powerup() { - fallHandler = new Heavy(); - } - private void checkFullLines() { int y = height - 1; int linesCleared = 0; @@ -338,6 +337,10 @@ public class Board { squares[y][x] = type; } + public void setFallHandler(FallHandler fallHandler) { + this.fallHandler = fallHandler; + } + public void togglePaused() { paused = !paused; } diff --git a/src/se/liu/gusso230/tetris/TetrisComponent.java b/src/se/liu/gusso230/tetris/TetrisComponent.java index 17705d6..79f34b2 100644 --- a/src/se/liu/gusso230/tetris/TetrisComponent.java +++ b/src/se/liu/gusso230/tetris/TetrisComponent.java @@ -26,13 +26,15 @@ public class TetrisComponent extends JComponent implements BoardListener { this.getInputMap().put(KeyStroke.getKeyStroke("RIGHT"), "moveRight"); this.getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "rotateLeft"); this.getInputMap().put(KeyStroke.getKeyStroke("UP"), "rotateRight"); - this.getInputMap().put(KeyStroke.getKeyStroke('e'), "powerup"); + this.getInputMap().put(KeyStroke.getKeyStroke('q'), "fallthrough"); + this.getInputMap().put(KeyStroke.getKeyStroke('e'), "heavy"); 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)); - this.getActionMap().put("powerup", new PowerUpAction()); + this.getActionMap().put("fallthrough", new PowerUpAction(new Fallthrough())); + this.getActionMap().put("heavy", new PowerUpAction(new Heavy())); } private class MoveAction extends AbstractAction { @@ -58,10 +60,13 @@ public class TetrisComponent extends JComponent implements BoardListener { } private class PowerUpAction extends AbstractAction { - private PowerUpAction() {} + private FallHandler fallHandler; + private PowerUpAction(final FallHandler fallHandler) { + this.fallHandler = fallHandler; + } @Override public void actionPerformed(final ActionEvent actionEvent) { - board.powerup(); + board.setFallHandler(fallHandler); } } -- cgit v1.2.1