diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-12 10:49:39 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-12 10:49:39 +0100 |
| commit | 8c9d99e6e8cc05897e72da58bc9347830a267849 (patch) | |
| tree | 587106e75ccfef84ce3953b3cbd8eb05ed5377b5 /src/se | |
| parent | 60603300a6a39de4c81b592a4263af0b91c7cbc1 (diff) | |
| download | tdde30-8c9d99e6e8cc05897e72da58bc9347830a267849.tar.gz | |
4.8
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(); |
