summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-03-04 10:06:25 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-03-04 10:06:25 +0100
commitaa52b34d25e41758e51289a130ab893e7dbc550d (patch)
treedc734f2c519d80a36b2574ddc437bf29a929259f
parentb94992ce6233f3986d34855dea82c839fb2cdf37 (diff)
downloadtdde30-aa52b34d25e41758e51289a130ab893e7dbc550d.tar.gz
only check lines if placed falling piece
-rw-r--r--src/se/liu/gusso230/tetris/Board.java13
-rw-r--r--src/se/liu/gusso230/tetris/TetrisComponent.java13
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);
}
}