Save time mode high score

This commit is contained in:
Lonami Exo 2017-02-05 14:55:39 +01:00
parent d35c8481e5
commit 6dd3861f0e
3 changed files with 12 additions and 9 deletions

View file

@ -99,6 +99,10 @@ public class Klooni extends Game {
prefs.putInteger("maxScore", score).flush();
}
public static void setMaxTimeScore(int maxTimeScore) {
prefs.putInteger("maxTimeScore", maxTimeScore).flush();
}
public static boolean soundsEnabled() {
return !prefs.getBoolean("muteSound", false);
}

View file

@ -15,9 +15,6 @@ public class Scorer extends BaseScorer {
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
private float shownScore;
@ -40,7 +37,6 @@ public class Scorer extends BaseScorer {
@Override
protected void addScore(int score) {
currentScore += score;
newRecord = currentScore > maxScore;
}
//endregion
@ -52,14 +48,14 @@ public class Scorer extends BaseScorer {
}
public void saveScore() {
if (newRecord) {
if (isNewRecord()) {
Klooni.setMaxScore(currentScore);
}
}
@Override
protected boolean isNewRecord() {
return newRecord;
return currentScore > maxScore;
}
@Override

View file

@ -11,6 +11,7 @@ public class TimeScorer extends BaseScorer {
//region Members
private long startTime;
private final int highScoreTime;
// 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`
@ -29,6 +30,7 @@ public class TimeScorer extends BaseScorer {
// The board size is required when calculating the score
public TimeScorer(final Klooni game, GameLayout layout) {
super(game, layout, Klooni.getMaxTimeScore());
highScoreTime = Klooni.getMaxTimeScore();
startTime = TimeUtils.nanoTime();
deadTime = startTime + START_TIME;
@ -74,13 +76,14 @@ public class TimeScorer extends BaseScorer {
@Override
public void saveScore() {
// TODO Save high time score
if (isNewRecord()) {
Klooni.setMaxTimeScore(getCurrentScore());
}
}
@Override
protected boolean isNewRecord() {
// TODO Return true if it is a new record
return false;
return getCurrentScore() > highScoreTime;
}
@Override