diff options
Diffstat (limited to 'src/se')
| -rw-r--r-- | src/se/liu/gusso230/tetris/Board.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/se/liu/gusso230/tetris/Board.java b/src/se/liu/gusso230/tetris/Board.java index d176dee..1864e9f 100644 --- a/src/se/liu/gusso230/tetris/Board.java +++ b/src/se/liu/gusso230/tetris/Board.java @@ -45,6 +45,8 @@ public class Board { moveFalling(); } } + + checkFullLines(); } private void moveFalling() { @@ -70,6 +72,7 @@ public class Board { private boolean hasFallingCollision() { return !falling.onlyCoversEmpty(fallingX, fallingY, this); } + private boolean fallingIsOutside() { return !falling.isInside(fallingX, fallingY, 0, width - 1, 0, height - 1); } @@ -118,6 +121,32 @@ public class Board { notifyListeners(); } + private void checkFullLines() { + int y = height - 1; + while (y >= 0) { + boolean hole = false; + for (int x = 0; x < width; x++) { + if (squares[y][x] == SquareType.EMPTY) { + hole = true; + break; + } + } + if (hole) { + y--; + } else { + moveDownFrom(y); + } + } + } + + private void moveDownFrom(int 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]; + } + } + } + private void placeAt(Poly poly, int x, int y) { for (Point pt : poly.getPoints()) { squares[y + pt.getY()][x + pt.getX()] = poly.getSquareType(); |
