diff options
Diffstat (limited to 'app/src/main/java/com/camilstaps/rushhour')
| -rw-r--r-- | app/src/main/java/com/camilstaps/rushhour/HighScore.java | 19 | ||||
| -rw-r--r-- | app/src/main/java/com/camilstaps/rushhour/HighScoreList.java | 29 | 
2 files changed, 47 insertions, 1 deletions
diff --git a/app/src/main/java/com/camilstaps/rushhour/HighScore.java b/app/src/main/java/com/camilstaps/rushhour/HighScore.java index 87c9816..ce5e001 100644 --- a/app/src/main/java/com/camilstaps/rushhour/HighScore.java +++ b/app/src/main/java/com/camilstaps/rushhour/HighScore.java @@ -2,8 +2,9 @@ package com.camilstaps.rushhour;  /**   * Created by camilstaps on 23-4-15. + * Edited by Halzyn on 23-4-15.   */ -public class HighScore { +public class HighScore implements Comparable<HighScore> {      private final int score;      private final String name; @@ -21,4 +22,20 @@ public class HighScore {          return name;      } +    @Override +    public int compareTo(HighScore other_score) { +        if (other_score.getScore() < score) +        { +            return -1; +        } +        else if (other_score.getScore() == score) +        { +            return 0; +        } +        else +        { +            return 1; +        } +    } +  } diff --git a/app/src/main/java/com/camilstaps/rushhour/HighScoreList.java b/app/src/main/java/com/camilstaps/rushhour/HighScoreList.java new file mode 100644 index 0000000..c0a7e67 --- /dev/null +++ b/app/src/main/java/com/camilstaps/rushhour/HighScoreList.java @@ -0,0 +1,29 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package rushhour; + +import java.util.Collections; +import java.util.List; + +/** + * + * @author Created by halzyn on 23-4-15. + */ +public class HighScoreList { +     +    private List<HighScore> list; +     +    public HighScoreList (List<HighScore> some_list) { +        this.list = some_list; +    } +     +    public void addToList(HighScore score) +    { +        list.add(score); +        Collections.sort(list); +    } +    +}  | 
