Replace post-increment with pre-decrement
This commit is contained in:
parent
0aba6d1724
commit
07fed37697
5 changed files with 43 additions and 43 deletions
|
@ -55,7 +55,7 @@ public class Theme {
|
||||||
FileHandle[] handles = Gdx.files.internal("themes").list();
|
FileHandle[] handles = Gdx.files.internal("themes").list();
|
||||||
|
|
||||||
Theme[] result = new Theme[handles.length];
|
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]);
|
result[i] = Theme.fromFile(handles[i]);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -95,7 +95,7 @@ public class Theme {
|
||||||
|
|
||||||
JsonValue buttonColors = colors.get("buttons");
|
JsonValue buttonColors = colors.get("buttons");
|
||||||
buttons = new Color[buttonColors.size];
|
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));
|
buttons[i] = new Color((int)Long.parseLong(buttonColors.getString(i), 16));
|
||||||
if (buttonStyles[i] == null) {
|
if (buttonStyles[i] == null) {
|
||||||
buttonStyles[i] = new ImageButton.ImageButtonStyle();
|
buttonStyles[i] = new ImageButton.ImageButtonStyle();
|
||||||
|
@ -114,7 +114,7 @@ public class Theme {
|
||||||
|
|
||||||
JsonValue cellColors = colors.get("cells");
|
JsonValue cellColors = colors.get("cells");
|
||||||
cells = new Color[cellColors.size];
|
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));
|
cells[i] = new Color((int)Long.parseLong(cellColors.getString(i), 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ public class Board {
|
||||||
// Cell size depends on the layout to be updated first
|
// Cell size depends on the layout to be updated first
|
||||||
layout.update(this);
|
layout.update(this);
|
||||||
cells = new Cell[this.cellCount][this.cellCount];
|
cells = new Cell[this.cellCount][this.cellCount];
|
||||||
for (int i = 0; i < this.cellCount; i++) {
|
for (int i = 0; i < this.cellCount; ++i) {
|
||||||
for (int j = 0; j < this.cellCount; j++) {
|
for (int j = 0; j < this.cellCount; ++j) {
|
||||||
cells[i][j] = new Cell(
|
cells[i][j] = new Cell(
|
||||||
pos.x + j * cellSize, pos.y + i * cellSize, cellSize);
|
pos.x + j * cellSize, pos.y + i * cellSize, cellSize);
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ public class Board {
|
||||||
if (!inBounds(piece, x, y))
|
if (!inBounds(piece, x, y))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (int i = 0; i < piece.cellRows; i++)
|
for (int i = 0; i < piece.cellRows; ++i)
|
||||||
for (int j = 0; j < piece.cellCols; j++)
|
for (int j = 0; j < piece.cellCols; ++j)
|
||||||
if (!cells[y+i][x+j].isEmpty() && piece.filled(i, j))
|
if (!cells[y+i][x+j].isEmpty() && piece.filled(i, j))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ public class Board {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
lastPutPiecePos.set(piece.calculateGravityCenter());
|
lastPutPiecePos.set(piece.calculateGravityCenter());
|
||||||
for (int i = 0; i < piece.cellRows; i++) {
|
for (int i = 0; i < piece.cellRows; ++i) {
|
||||||
for (int j = 0; j < piece.cellCols; j++) {
|
for (int j = 0; j < piece.cellCols; ++j) {
|
||||||
if (piece.filled(i, j)) {
|
if (piece.filled(i, j)) {
|
||||||
cells[y+i][x+j].set(piece.color);
|
cells[y+i][x+j].set(piece.color);
|
||||||
}
|
}
|
||||||
|
@ -96,14 +96,14 @@ public class Board {
|
||||||
//region Public methods
|
//region Public methods
|
||||||
|
|
||||||
public void draw(SpriteBatch batch) {
|
public void draw(SpriteBatch batch) {
|
||||||
for (int i = 0; i < cellCount; i++)
|
for (int i = 0; i < cellCount; ++i)
|
||||||
for (int j = 0; j < cellCount; j++)
|
for (int j = 0; j < cellCount; ++j)
|
||||||
cells[i][j].draw(batch);
|
cells[i][j].draw(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canPutPiece(Piece piece) {
|
public boolean canPutPiece(Piece piece) {
|
||||||
for (int i = 0; i < cellCount; i++)
|
for (int i = 0; i < cellCount; ++i)
|
||||||
for (int j = 0; j < cellCount; j++)
|
for (int j = 0; j < cellCount; ++j)
|
||||||
if (canPutPiece(piece, j, i))
|
if (canPutPiece(piece, j, i))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -137,9 +137,9 @@ public class Board {
|
||||||
boolean[] clearedCols = new boolean[cellCount];
|
boolean[] clearedCols = new boolean[cellCount];
|
||||||
|
|
||||||
// Analyze rows and columns that will be cleared
|
// 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;
|
clearedRows[i] = true;
|
||||||
for (int j = 0; j < cellCount; j++) {
|
for (int j = 0; j < cellCount; ++j) {
|
||||||
if (cells[i][j].isEmpty()) {
|
if (cells[i][j].isEmpty()) {
|
||||||
clearedRows[i] = false;
|
clearedRows[i] = false;
|
||||||
break;
|
break;
|
||||||
|
@ -148,9 +148,9 @@ public class Board {
|
||||||
if (clearedRows[i])
|
if (clearedRows[i])
|
||||||
clearCount++;
|
clearCount++;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < cellCount; j++) {
|
for (int j = 0; j < cellCount; ++j) {
|
||||||
clearedCols[j] = true;
|
clearedCols[j] = true;
|
||||||
for (int i = 0; i < cellCount; i++) {
|
for (int i = 0; i < cellCount; ++i) {
|
||||||
if (cells[i][j].isEmpty()) {
|
if (cells[i][j].isEmpty()) {
|
||||||
clearedCols[j] = false;
|
clearedCols[j] = false;
|
||||||
break;
|
break;
|
||||||
|
@ -163,15 +163,15 @@ public class Board {
|
||||||
float pan = 0;
|
float pan = 0;
|
||||||
|
|
||||||
// Do clear those rows and columns
|
// Do clear those rows and columns
|
||||||
for (int i = 0; i < cellCount; i++)
|
for (int i = 0; i < cellCount; ++i)
|
||||||
if (clearedRows[i])
|
if (clearedRows[i])
|
||||||
for (int j = 0; j < cellCount; j++)
|
for (int j = 0; j < cellCount; ++j)
|
||||||
cells[i][j].vanish(lastPutPiecePos);
|
cells[i][j].vanish(lastPutPiecePos);
|
||||||
|
|
||||||
for (int j = 0; j < cellCount; j++) {
|
for (int j = 0; j < cellCount; ++j) {
|
||||||
if (clearedCols[j]) {
|
if (clearedCols[j]) {
|
||||||
pan += 2f * (j - cellCount / 2) / (float)cellCount;
|
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);
|
cells[i][j].vanish(lastPutPiecePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ public class Piece {
|
||||||
cellCols = swapSize ? rows : cols;
|
cellCols = swapSize ? rows : cols;
|
||||||
cellRows = swapSize ? cols : rows;
|
cellRows = swapSize ? cols : rows;
|
||||||
shape = new boolean[cellRows][cellCols];
|
shape = new boolean[cellRows][cellCols];
|
||||||
for (int i = 0; i < cellRows; i++) {
|
for (int i = 0; i < cellRows; ++i) {
|
||||||
for (int j = 0; j < cellCols; j++) {
|
for (int j = 0; j < cellCols; ++j) {
|
||||||
shape[i][j] = true;
|
shape[i][j] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,27 +56,27 @@ public class Piece {
|
||||||
shape = new boolean[lSize][lSize];
|
shape = new boolean[lSize][lSize];
|
||||||
switch (rotateCount % 4) {
|
switch (rotateCount % 4) {
|
||||||
case 0: // ┌
|
case 0: // ┌
|
||||||
for (int j = 0; j < lSize; j++)
|
for (int j = 0; j < lSize; ++j)
|
||||||
shape[0][j] = true;
|
shape[0][j] = true;
|
||||||
for (int i = 0; i < lSize; i++)
|
for (int i = 0; i < lSize; ++i)
|
||||||
shape[i][0] = true;
|
shape[i][0] = true;
|
||||||
break;
|
break;
|
||||||
case 1: // ┐
|
case 1: // ┐
|
||||||
for (int j = 0; j < lSize; j++)
|
for (int j = 0; j < lSize; ++j)
|
||||||
shape[0][j] = true;
|
shape[0][j] = true;
|
||||||
for (int i = 0; i < lSize; i++)
|
for (int i = 0; i < lSize; ++i)
|
||||||
shape[i][lSize-1] = true;
|
shape[i][lSize-1] = true;
|
||||||
break;
|
break;
|
||||||
case 2: // ┘
|
case 2: // ┘
|
||||||
for (int j = 0; j < lSize; j++)
|
for (int j = 0; j < lSize; ++j)
|
||||||
shape[lSize-1][j] = true;
|
shape[lSize-1][j] = true;
|
||||||
for (int i = 0; i < lSize; i++)
|
for (int i = 0; i < lSize; ++i)
|
||||||
shape[i][lSize-1] = true;
|
shape[i][lSize-1] = true;
|
||||||
break;
|
break;
|
||||||
case 3: // └
|
case 3: // └
|
||||||
for (int j = 0; j < lSize; j++)
|
for (int j = 0; j < lSize; ++j)
|
||||||
shape[lSize-1][j] = true;
|
shape[lSize-1][j] = true;
|
||||||
for (int i = 0; i < lSize; i++)
|
for (int i = 0; i < lSize; ++i)
|
||||||
shape[i][0] = true;
|
shape[i][0] = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,8 @@ public class Piece {
|
||||||
//region Package local methods
|
//region Package local methods
|
||||||
|
|
||||||
void draw(SpriteBatch batch) {
|
void draw(SpriteBatch batch) {
|
||||||
for (int i = 0; i < cellRows; i++)
|
for (int i = 0; i < cellRows; ++i)
|
||||||
for (int j = 0; j < cellCols; j++)
|
for (int j = 0; j < cellCols; ++j)
|
||||||
if (shape[i][j])
|
if (shape[i][j])
|
||||||
Cell.draw(color, batch, pos.x + j * cellSize, pos.y + i * cellSize, cellSize);
|
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
|
// Calculates the area occupied by the shape
|
||||||
int calculateArea() {
|
int calculateArea() {
|
||||||
int area = 0;
|
int area = 0;
|
||||||
for (int i = 0; i < cellRows; i++) {
|
for (int i = 0; i < cellRows; ++i) {
|
||||||
for (int j = 0; j < cellCols; j++) {
|
for (int j = 0; j < cellCols; ++j) {
|
||||||
if (shape[i][j]) {
|
if (shape[i][j]) {
|
||||||
area++;
|
area++;
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,8 @@ public class Piece {
|
||||||
Vector2 calculateGravityCenter() {
|
Vector2 calculateGravityCenter() {
|
||||||
int filledCount = 0;
|
int filledCount = 0;
|
||||||
Vector2 result = new Vector2();
|
Vector2 result = new Vector2();
|
||||||
for (int i = 0; i < cellRows; i++) {
|
for (int i = 0; i < cellRows; ++i) {
|
||||||
for (int j = 0; j < cellCols; j++) {
|
for (int j = 0; j < cellCols; ++j) {
|
||||||
if (shape[i][j]) {
|
if (shape[i][j]) {
|
||||||
filledCount++;
|
filledCount++;
|
||||||
result.add(
|
result.add(
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class PieceHolder {
|
||||||
|
|
||||||
// Determines whether all the pieces have been put (and the "hand" is finished)
|
// Determines whether all the pieces have been put (and the "hand" is finished)
|
||||||
private boolean handFinished() {
|
private boolean handFinished() {
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; ++i)
|
||||||
if (pieces[i] != null)
|
if (pieces[i] != null)
|
||||||
return false;
|
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
|
// Takes a new set of pieces. Should be called when there are no more piece left
|
||||||
private void takeMore() {
|
private void takeMore() {
|
||||||
float perPieceWidth = area.width / count;
|
float perPieceWidth = area.width / count;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; ++i) {
|
||||||
pieces[i] = Piece.random();
|
pieces[i] = Piece.random();
|
||||||
|
|
||||||
// Set the absolute position on screen and the cells' cellSize
|
// Set the absolute position on screen and the cells' cellSize
|
||||||
|
@ -126,7 +126,7 @@ public class PieceHolder {
|
||||||
Gdx.input.getX(),
|
Gdx.input.getX(),
|
||||||
Gdx.graphics.getHeight() - Gdx.input.getY()); // Y axis is inverted
|
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)) {
|
if (pieces[i] != null && pieces[i].getRectangle().contains(mouse)) {
|
||||||
heldPiece = i;
|
heldPiece = i;
|
||||||
return true;
|
return true;
|
||||||
|
@ -139,7 +139,7 @@ public class PieceHolder {
|
||||||
|
|
||||||
public Array<Piece> getAvailablePieces() {
|
public Array<Piece> getAvailablePieces() {
|
||||||
Array<Piece> result = new Array<Piece>(count);
|
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)
|
if (pieces[i] != null)
|
||||||
result.add(pieces[i]);
|
result.add(pieces[i]);
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ public class PieceHolder {
|
||||||
// Return the pieces to their original position
|
// Return the pieces to their original position
|
||||||
// TODO This seems somewhat expensive, can't it be done any better?
|
// TODO This seems somewhat expensive, can't it be done any better?
|
||||||
Rectangle original;
|
Rectangle original;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; ++i) {
|
||||||
if (i == heldPiece)
|
if (i == heldPiece)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ public class PieceHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(SpriteBatch batch) {
|
public void draw(SpriteBatch batch) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; ++i) {
|
||||||
if (pieces[i] != null) {
|
if (pieces[i] != null) {
|
||||||
pieces[i].draw(batch);
|
pieces[i].draw(batch);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue