summaryrefslogtreecommitdiffstats
path: root/src/se
diff options
context:
space:
mode:
Diffstat (limited to 'src/se')
-rw-r--r--src/se/liu/gusso230/tetris/Board.java6
-rw-r--r--src/se/liu/gusso230/tetris/DefaultFallHandler.java4
-rw-r--r--src/se/liu/gusso230/tetris/FallHandler.java1
-rw-r--r--src/se/liu/gusso230/tetris/Fallthrough.java11
-rw-r--r--src/se/liu/gusso230/tetris/Poly.java14
5 files changed, 31 insertions, 5 deletions
diff --git a/src/se/liu/gusso230/tetris/Board.java b/src/se/liu/gusso230/tetris/Board.java
index 678e0fb..3d1d8d0 100644
--- a/src/se/liu/gusso230/tetris/Board.java
+++ b/src/se/liu/gusso230/tetris/Board.java
@@ -35,7 +35,7 @@ public class Board {
private int timerDelay;
private List<BoardListener> boardListeners;
- private FallHandler fallHandler = new DefaultFallHandler();
+ private FallHandler fallHandler = new Fallthrough();
private final static Random RND = new Random();
@@ -224,13 +224,13 @@ public class Board {
break;
}
if (clearedLines > 0) {
- timerDelay *= (int) 0.95;
+ timerDelay = (int) (timerDelay * 0.95);
timer.setDelay(timerDelay);
}
}
private void moveDownFrom(int line) {
- for (int y = line; y > 0; y--) { // > since we dont want to copy into the top line
+ for (int y = line; y > 0; y--) { // > since we dont want to copy into the top line
for (int x = 0; x < width; x++) {
squares[y][x] = squares[y-1][x];
}
diff --git a/src/se/liu/gusso230/tetris/DefaultFallHandler.java b/src/se/liu/gusso230/tetris/DefaultFallHandler.java
index e9269d8..180d8f4 100644
--- a/src/se/liu/gusso230/tetris/DefaultFallHandler.java
+++ b/src/se/liu/gusso230/tetris/DefaultFallHandler.java
@@ -4,4 +4,8 @@ public class DefaultFallHandler implements FallHandler {
@Override public boolean hasFallingCollision(final Board board) {
return !board.getFalling().onlyCoversEmpty(board.getFallingX(), board.getFallingY(), board);
}
+
+ @Override public String getDescription() {
+ return "No powerup";
+ }
}
diff --git a/src/se/liu/gusso230/tetris/FallHandler.java b/src/se/liu/gusso230/tetris/FallHandler.java
index 0e335d6..ed21d33 100644
--- a/src/se/liu/gusso230/tetris/FallHandler.java
+++ b/src/se/liu/gusso230/tetris/FallHandler.java
@@ -2,4 +2,5 @@ package se.liu.gusso230.tetris;
public interface FallHandler {
boolean hasFallingCollision(Board board);
+ String getDescription();
}
diff --git a/src/se/liu/gusso230/tetris/Fallthrough.java b/src/se/liu/gusso230/tetris/Fallthrough.java
new file mode 100644
index 0000000..add19fc
--- /dev/null
+++ b/src/se/liu/gusso230/tetris/Fallthrough.java
@@ -0,0 +1,11 @@
+package se.liu.gusso230.tetris;
+
+public class Fallthrough implements FallHandler {
+ @Override public boolean hasFallingCollision(final Board board) {
+ return !board.getFalling().isAtOrAbove(board.getFallingY(), board.getHeight());
+ }
+
+ @Override public String getDescription() {
+ return "Fallthrough";
+ }
+}
diff --git a/src/se/liu/gusso230/tetris/Poly.java b/src/se/liu/gusso230/tetris/Poly.java
index efd9b7e..8bd6b02 100644
--- a/src/se/liu/gusso230/tetris/Poly.java
+++ b/src/se/liu/gusso230/tetris/Poly.java
@@ -22,7 +22,7 @@ public class Poly {
}
/**
- * Returns wether this poly covers a position (x, y) if the top left corner
+ * Returns whether this poly covers a position (x, y) if the top left corner
* of the poly is at (posX, posY).
*
* @param posX The x position of the top left corner of the poly's bounding box.
@@ -40,7 +40,7 @@ public class Poly {
}
/**
- * Returns wether this poly is completely inside some box from (minX, minY)
+ * Returns whether this poly is completely inside some box from (minX, minY)
* to (maxX, maxY) if the top left corner of the poly is at (posX, posY).
*
* Where the "minimum" and "maximum" corners mentioned below are located depends on
@@ -70,6 +70,16 @@ public class Poly {
return true;
}
+ public boolean isAtOrAbove(int posY, int y) {
+ for (Point point : points) {
+ int pointY = posY + point.getY();
+ if (pointY > y) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* Rotates all the poly's points one step clockwise.
*/