Skip to content

Commit

Permalink
update rotating logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AlinaStepanova committed Mar 16, 2019
1 parent ad83991 commit 2e81d57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/com/example/alina/tetris/NetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 2e81d57

Please sign in to comment.