allow undo when the new pieces are generated since it is REALLY not that helpful and "gaming the system", also ver bump
This commit is contained in:
parent
d8a304c6e4
commit
fb12477c98
2 changed files with 19 additions and 4 deletions
|
@ -21,8 +21,8 @@ android {
|
|||
//noinspection MinSdkTooLow
|
||||
minSdkVersion 8
|
||||
targetSdkVersion 29
|
||||
versionCode 860
|
||||
versionName "0.8.6"
|
||||
versionCode 870
|
||||
versionName "0.8.7"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.badlogic.gdx.utils.Array;
|
|||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import dev.lonami.klooni.Klooni;
|
||||
import dev.lonami.klooni.serializer.BinSerializable;
|
||||
|
@ -42,6 +43,7 @@ public class PieceHolder implements BinSerializable {
|
|||
final Rectangle area;
|
||||
private final Piece[] pieces;
|
||||
private Piece lastPiece = null;
|
||||
private Piece[] drawnPieces = null;
|
||||
|
||||
private final Sound pieceDropSound;
|
||||
private final Sound invalidPieceDropSound;
|
||||
|
@ -112,11 +114,11 @@ public class PieceHolder implements BinSerializable {
|
|||
|
||||
// Takes a new set of pieces. Should be called when there are no more piece left
|
||||
private void takeMore() {
|
||||
lastPiece = null; // NO UNDO!
|
||||
for (int i = 0; i < count; ++i)
|
||||
pieces[i] = Piece.random();
|
||||
pieces[i] = drawnPieces != null ? drawnPieces[i] : Piece.random();
|
||||
updatePiecesStartLocation();
|
||||
|
||||
drawnPieces = null;
|
||||
if (Klooni.soundsEnabled()) {
|
||||
// Random pitch so it's not always the same sound
|
||||
takePiecesSound.play(1, MathUtils.random(0.8f, 1.2f), 0);
|
||||
|
@ -160,8 +162,21 @@ public class PieceHolder implements BinSerializable {
|
|||
|
||||
public boolean undo() {
|
||||
if(lastPiece != null) {
|
||||
int valid = 0;
|
||||
for (Piece piece : pieces) {
|
||||
if (piece != null) valid += 1;
|
||||
}
|
||||
if(valid == pieces.length) {
|
||||
drawnPieces = new Piece[pieces.length];
|
||||
for(int i = 0; i < pieces.length; i += 1) {
|
||||
drawnPieces[i] = pieces[i];
|
||||
pieces[i] = null;
|
||||
}
|
||||
}
|
||||
pieces[lastHeldPiece] = lastPiece;
|
||||
lastPiece = null;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue