diff --git a/app/src/main/java/com/example/alina/tetris/NetManager.java b/app/src/main/java/com/example/alina/tetris/NetManager.java index 226c892..934763e 100644 --- a/app/src/main/java/com/example/alina/tetris/NetManager.java +++ b/app/src/main/java/com/example/alina/tetris/NetManager.java @@ -34,6 +34,15 @@ public NetManager() { combo = 0; } + public boolean canRotate(Figure rotatedFigure) { + boolean result = false; + if (rotatedFigure.coordinatesInNet.x + rotatedFigure.getWidthInSquare() <= verticalSquareCount + && isNetFreeToMoveDown()) { + result = true; + } + return result; + } + private void setNet(boolean[][] net) { this.net = net; } @@ -116,6 +125,7 @@ private int getEndHorizontalPosition(boolean[] mask) { return trueCount; } + //todo think of rotated figure private boolean isFigureBelow() { boolean result = false; int coordinateX = figure.coordinatesInNet.x; @@ -310,8 +320,8 @@ public void moveDownInNet() { int endPosition = getEndHorizontalPosition(figure.figureMask[i - 1]); System.arraycopy(figure.figureMask[i - 1], startPosition, net[coordinateY + i], figure.coordinatesInNet.x + startPosition, endPosition); - for (int j = 0; j < zeroNet.length; j++) { - System.arraycopy(zeroNet[j], startPosition, net[coordinateY + i - 1], + for (boolean[] zero : zeroNet) { + System.arraycopy(zero, startPosition, net[coordinateY + i - 1], figure.coordinatesInNet.x + startPosition, endPosition); } } diff --git a/app/src/main/java/com/example/alina/tetris/views/PlayingArea.java b/app/src/main/java/com/example/alina/tetris/views/PlayingArea.java index 7398169..1685944 100644 --- a/app/src/main/java/com/example/alina/tetris/views/PlayingArea.java +++ b/app/src/main/java/com/example/alina/tetris/views/PlayingArea.java @@ -170,12 +170,14 @@ public void rotate() { && figureList.getLast().getRotatedFigure() != null) { Figure figure = FigureFactory.getFigure(figureList.getLast().getRotatedFigure(), widthOfSquareSide, scale, context, figureList.getLast().point); - figureList.set(figureList.size() - 1, figure); if (figure != null) { figure.initFigureMask(); } - resetFiguresScale(netManager.checkBottomLine()); - netManager.initRotatedFigure(figure); + if (netManager.canRotate(figure)) { + figureList.set(figureList.size() - 1, figure); + resetFiguresScale(netManager.checkBottomLine()); + netManager.initRotatedFigure(figure); + } } }