Skip to content

Commit

Permalink
Save time mode high score
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Feb 5, 2017
1 parent d35c848 commit 6dd3861
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions core/src/io/github/lonamiwebs/klooni/Klooni.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public static void setMaxScore(int score) {
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);
}
Expand Down
8 changes: 2 additions & 6 deletions core/src/io/github/lonamiwebs/klooni/game/Scorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,7 +37,6 @@ public Scorer(final Klooni game, GameLayout layout) {
@Override
protected void addScore(int score) {
currentScore += score;
newRecord = currentScore > maxScore;
}

//endregion
Expand All @@ -52,14 +48,14 @@ public int getCurrentScore() {
}

public void saveScore() {
if (newRecord) {
if (isNewRecord()) {
Klooni.setMaxScore(currentScore);
}
}

@Override
protected boolean isNewRecord() {
return newRecord;
return currentScore > maxScore;
}

@Override
Expand Down
9 changes: 6 additions & 3 deletions core/src/io/github/lonamiwebs/klooni/game/TimeScorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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;
Expand Down Expand Up @@ -74,13 +76,14 @@ public boolean isGameOver() {

@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
Expand Down

0 comments on commit 6dd3861

Please sign in to comment.