Save time mode high score
This commit is contained in:
parent
d35c8481e5
commit
6dd3861f0e
3 changed files with 12 additions and 9 deletions
|
@ -99,6 +99,10 @@ public class Klooni extends Game {
|
||||||
prefs.putInteger("maxScore", score).flush();
|
prefs.putInteger("maxScore", score).flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setMaxTimeScore(int maxTimeScore) {
|
||||||
|
prefs.putInteger("maxTimeScore", maxTimeScore).flush();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean soundsEnabled() {
|
public static boolean soundsEnabled() {
|
||||||
return !prefs.getBoolean("muteSound", false);
|
return !prefs.getBoolean("muteSound", false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,6 @@ public class Scorer extends BaseScorer {
|
||||||
|
|
||||||
private int currentScore, maxScore;
|
private int currentScore, maxScore;
|
||||||
|
|
||||||
// If the currentScore beat the maxScore, then we have a new record
|
|
||||||
private boolean newRecord;
|
|
||||||
|
|
||||||
// To interpolate between shown score -> real score
|
// To interpolate between shown score -> real score
|
||||||
private float shownScore;
|
private float shownScore;
|
||||||
|
|
||||||
|
@ -40,7 +37,6 @@ public class Scorer extends BaseScorer {
|
||||||
@Override
|
@Override
|
||||||
protected void addScore(int score) {
|
protected void addScore(int score) {
|
||||||
currentScore += score;
|
currentScore += score;
|
||||||
newRecord = currentScore > maxScore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
@ -52,14 +48,14 @@ public class Scorer extends BaseScorer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveScore() {
|
public void saveScore() {
|
||||||
if (newRecord) {
|
if (isNewRecord()) {
|
||||||
Klooni.setMaxScore(currentScore);
|
Klooni.setMaxScore(currentScore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isNewRecord() {
|
protected boolean isNewRecord() {
|
||||||
return newRecord;
|
return currentScore > maxScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class TimeScorer extends BaseScorer {
|
||||||
//region Members
|
//region Members
|
||||||
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
private final int highScoreTime;
|
||||||
|
|
||||||
// Indicates where we would die in time. Score adds to this, so we take
|
// Indicates where we would die in time. Score adds to this, so we take
|
||||||
// longer to die. To get the "score" we simply calculate `deadTime - startTime`
|
// longer to die. To get the "score" we simply calculate `deadTime - startTime`
|
||||||
|
@ -29,6 +30,7 @@ public class TimeScorer extends BaseScorer {
|
||||||
// The board size is required when calculating the score
|
// The board size is required when calculating the score
|
||||||
public TimeScorer(final Klooni game, GameLayout layout) {
|
public TimeScorer(final Klooni game, GameLayout layout) {
|
||||||
super(game, layout, Klooni.getMaxTimeScore());
|
super(game, layout, Klooni.getMaxTimeScore());
|
||||||
|
highScoreTime = Klooni.getMaxTimeScore();
|
||||||
|
|
||||||
startTime = TimeUtils.nanoTime();
|
startTime = TimeUtils.nanoTime();
|
||||||
deadTime = startTime + START_TIME;
|
deadTime = startTime + START_TIME;
|
||||||
|
@ -74,13 +76,14 @@ public class TimeScorer extends BaseScorer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveScore() {
|
public void saveScore() {
|
||||||
// TODO Save high time score
|
if (isNewRecord()) {
|
||||||
|
Klooni.setMaxTimeScore(getCurrentScore());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isNewRecord() {
|
protected boolean isNewRecord() {
|
||||||
// TODO Return true if it is a new record
|
return getCurrentScore() > highScoreTime;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue