-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScore.java
98 lines (87 loc) · 2.58 KB
/
Score.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Constructor for a score object and a method to compare two scores.
package model;
// Has a constructor to create a score object and a method to compare two scores.
public class Score implements Comparable<Score> {
private String name; //Name of the Player with high Score
private int score; // Highscore
private DifficultyType difficultyType; //Difficulty Type of the game
/**
* Constructor for the Score Class
*
* @param name - Name of the Player with High Score
* @param score - HighScore
* @param difficultyType - Difficulty Type of the game
* @author
*/
public Score(String name, int score, DifficultyType difficultyType) {
this.name = name; // Name of the player with highscore
this.score = score;
this.difficultyType = difficultyType;
}
/**
*
* @return - returns the name of the player.
*/
public String getName() {
return name;
}
/**
* Takes a string(name) as input for the player's name and sets the name to this string.
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* @return - returns the score of the player.
*/
public int getScore() {
return score;
}
/**
* Takes an int(score) as input for the player's score and sets the score to this value.
*
* @param score
*/
public void setScore(int score) {
this.score = score;
}
/**
*
* @return- returns the DifficultyType of the game (EASY, MEDIUM, HARD or CUSTOM).
*/
public DifficultyType getDifficultyType() {
return difficultyType;
}
/**
* Sets the DifficultyType of the game to EASY, MEDIUM, HARD or CUSTOM as selected by the player.
*
* @param difficultyType
*/
public void setDifficultyType(DifficultyType difficultyType) {
this.difficultyType = difficultyType;
}
/**
* Parses the Score Object to String
* @return String
*/
@Override
public String toString() {
return "Score [difficultyType=" + difficultyType + ", name=" + name + ", score=" + score + "]";
}
// compares two scores to see which score is greater.
public int compareTo(Score scoreObj) {
int scoreToCompare = ((Score) scoreObj).getScore(); // making sure the object is of the same type
if (this.score > scoreToCompare) {
return 1;
}
else if (this.score < scoreToCompare){
return -1;
}
else {
return 0;
}
}
}