Replace post-increment with pre-decrement

This commit is contained in:
Lonami Exo 2017-02-06 16:22:47 +01:00
parent 0aba6d1724
commit 07fed37697
5 changed files with 43 additions and 43 deletions

View file

@ -55,7 +55,7 @@ public class Theme {
FileHandle[] handles = Gdx.files.internal("themes").list();
Theme[] result = new Theme[handles.length];
for (int i = 0; i < handles.length; i++)
for (int i = 0; i < handles.length; ++i)
result[i] = Theme.fromFile(handles[i]);
return result;
@ -95,7 +95,7 @@ public class Theme {
JsonValue buttonColors = colors.get("buttons");
buttons = new Color[buttonColors.size];
for (int i = 0; i < buttons.length; i++) {
for (int i = 0; i < buttons.length; ++i) {
buttons[i] = new Color((int)Long.parseLong(buttonColors.getString(i), 16));
if (buttonStyles[i] == null) {
buttonStyles[i] = new ImageButton.ImageButtonStyle();
@ -114,7 +114,7 @@ public class Theme {
JsonValue cellColors = colors.get("cells");
cells = new Color[cellColors.size];
for (int i = 0; i < cells.length; i++) {
for (int i = 0; i < cells.length; ++i) {
cells[i] = new Color((int)Long.parseLong(cellColors.getString(i), 16));
}

View file

@ -39,8 +39,8 @@ public class Board {
// Cell size depends on the layout to be updated first
layout.update(this);
cells = new Cell[this.cellCount][this.cellCount];
for (int i = 0; i < this.cellCount; i++) {
for (int j = 0; j < this.cellCount; j++) {
for (int i = 0; i < this.cellCount; ++i) {
for (int j = 0; j < this.cellCount; ++j) {
cells[i][j] = new Cell(
pos.x + j * cellSize, pos.y + i * cellSize, cellSize);
}
@ -66,8 +66,8 @@ public class Board {
if (!inBounds(piece, x, y))
return false;
for (int i = 0; i < piece.cellRows; i++)
for (int j = 0; j < piece.cellCols; j++)
for (int i = 0; i < piece.cellRows; ++i)
for (int j = 0; j < piece.cellCols; ++j)
if (!cells[y+i][x+j].isEmpty() && piece.filled(i, j))
return false;
@ -80,8 +80,8 @@ public class Board {
return false;
lastPutPiecePos.set(piece.calculateGravityCenter());
for (int i = 0; i < piece.cellRows; i++) {
for (int j = 0; j < piece.cellCols; j++) {
for (int i = 0; i < piece.cellRows; ++i) {
for (int j = 0; j < piece.cellCols; ++j) {
if (piece.filled(i, j)) {
cells[y+i][x+j].set(piece.color);
}
@ -96,14 +96,14 @@ public class Board {
//region Public methods
public void draw(SpriteBatch batch) {
for (int i = 0; i < cellCount; i++)
for (int j = 0; j < cellCount; j++)
for (int i = 0; i < cellCount; ++i)
for (int j = 0; j < cellCount; ++j)
cells[i][j].draw(batch);
}
public boolean canPutPiece(Piece piece) {
for (int i = 0; i < cellCount; i++)
for (int j = 0; j < cellCount; j++)
for (int i = 0; i < cellCount; ++i)
for (int j = 0; j < cellCount; ++j)
if (canPutPiece(piece, j, i))
return true;
@ -137,9 +137,9 @@ public class Board {
boolean[] clearedCols = new boolean[cellCount];
// Analyze rows and columns that will be cleared
for (int i = 0; i < cellCount; i++) {
for (int i = 0; i < cellCount; ++i) {
clearedRows[i] = true;
for (int j = 0; j < cellCount; j++) {
for (int j = 0; j < cellCount; ++j) {
if (cells[i][j].isEmpty()) {
clearedRows[i] = false;
break;
@ -148,9 +148,9 @@ public class Board {
if (clearedRows[i])
clearCount++;
}
for (int j = 0; j < cellCount; j++) {
for (int j = 0; j < cellCount; ++j) {
clearedCols[j] = true;
for (int i = 0; i < cellCount; i++) {
for (int i = 0; i < cellCount; ++i) {
if (cells[i][j].isEmpty()) {
clearedCols[j] = false;
break;
@ -163,15 +163,15 @@ public class Board {
float pan = 0;
// Do clear those rows and columns
for (int i = 0; i < cellCount; i++)
for (int i = 0; i < cellCount; ++i)
if (clearedRows[i])
for (int j = 0; j < cellCount; j++)
for (int j = 0; j < cellCount; ++j)
cells[i][j].vanish(lastPutPiecePos);
for (int j = 0; j < cellCount; j++) {
for (int j = 0; j < cellCount; ++j) {
if (clearedCols[j]) {
pan += 2f * (j - cellCount / 2) / (float)cellCount;
for (int i = 0; i < cellCount; i++) {
for (int i = 0; i < cellCount; ++i) {
cells[i][j].vanish(lastPutPiecePos);
}
}

View file

@ -40,8 +40,8 @@ public class Piece {
cellCols = swapSize ? rows : cols;
cellRows = swapSize ? cols : rows;
shape = new boolean[cellRows][cellCols];
for (int i = 0; i < cellRows; i++) {
for (int j = 0; j < cellCols; j++) {
for (int i = 0; i < cellRows; ++i) {
for (int j = 0; j < cellCols; ++j) {
shape[i][j] = true;
}
}
@ -56,27 +56,27 @@ public class Piece {
shape = new boolean[lSize][lSize];
switch (rotateCount % 4) {
case 0: //
for (int j = 0; j < lSize; j++)
for (int j = 0; j < lSize; ++j)
shape[0][j] = true;
for (int i = 0; i < lSize; i++)
for (int i = 0; i < lSize; ++i)
shape[i][0] = true;
break;
case 1: //
for (int j = 0; j < lSize; j++)
for (int j = 0; j < lSize; ++j)
shape[0][j] = true;
for (int i = 0; i < lSize; i++)
for (int i = 0; i < lSize; ++i)
shape[i][lSize-1] = true;
break;
case 2: //
for (int j = 0; j < lSize; j++)
for (int j = 0; j < lSize; ++j)
shape[lSize-1][j] = true;
for (int i = 0; i < lSize; i++)
for (int i = 0; i < lSize; ++i)
shape[i][lSize-1] = true;
break;
case 3: //
for (int j = 0; j < lSize; j++)
for (int j = 0; j < lSize; ++j)
shape[lSize-1][j] = true;
for (int i = 0; i < lSize; i++)
for (int i = 0; i < lSize; ++i)
shape[i][0] = true;
break;
}
@ -113,8 +113,8 @@ public class Piece {
//region Package local methods
void draw(SpriteBatch batch) {
for (int i = 0; i < cellRows; i++)
for (int j = 0; j < cellCols; j++)
for (int i = 0; i < cellRows; ++i)
for (int j = 0; j < cellCols; ++j)
if (shape[i][j])
Cell.draw(color, batch, pos.x + j * cellSize, pos.y + i * cellSize, cellSize);
}
@ -132,8 +132,8 @@ public class Piece {
// Calculates the area occupied by the shape
int calculateArea() {
int area = 0;
for (int i = 0; i < cellRows; i++) {
for (int j = 0; j < cellCols; j++) {
for (int i = 0; i < cellRows; ++i) {
for (int j = 0; j < cellCols; ++j) {
if (shape[i][j]) {
area++;
}
@ -146,8 +146,8 @@ public class Piece {
Vector2 calculateGravityCenter() {
int filledCount = 0;
Vector2 result = new Vector2();
for (int i = 0; i < cellRows; i++) {
for (int j = 0; j < cellCols; j++) {
for (int i = 0; i < cellRows; ++i) {
for (int j = 0; j < cellCols; ++j) {
if (shape[i][j]) {
filledCount++;
result.add(

View file

@ -76,7 +76,7 @@ public class PieceHolder {
// Determines whether all the pieces have been put (and the "hand" is finished)
private boolean handFinished() {
for (int i = 0; i < count; i++)
for (int i = 0; i < count; ++i)
if (pieces[i] != null)
return false;
@ -86,7 +86,7 @@ public class PieceHolder {
// Takes a new set of pieces. Should be called when there are no more piece left
private void takeMore() {
float perPieceWidth = area.width / count;
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
pieces[i] = Piece.random();
// Set the absolute position on screen and the cells' cellSize
@ -126,7 +126,7 @@ public class PieceHolder {
Gdx.input.getX(),
Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
if (pieces[i] != null && pieces[i].getRectangle().contains(mouse)) {
heldPiece = i;
return true;
@ -139,7 +139,7 @@ public class PieceHolder {
public Array<Piece> getAvailablePieces() {
Array<Piece> result = new Array<Piece>(count);
for (int i = 0; i < count; i++)
for (int i = 0; i < count; ++i)
if (pieces[i] != null)
result.add(pieces[i]);
@ -206,7 +206,7 @@ public class PieceHolder {
// Return the pieces to their original position
// TODO This seems somewhat expensive, can't it be done any better?
Rectangle original;
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
if (i == heldPiece)
continue;
@ -221,7 +221,7 @@ public class PieceHolder {
}
public void draw(SpriteBatch batch) {
for (int i = 0; i < count; i++) {
for (int i = 0; i < count; ++i) {
if (pieces[i] != null) {
pieces[i].draw(batch);
}