package cse1030;
public class GameScore {
private static GameScore INSTANCE = new GameScore();
private int score;
private GameScore() {
this.score = 0;
}
/**
* Get the single instance of the game score manager.
*
* @return The single instance of the game score manager.
*/
public static GameScore getInstance() {
return GameScore.INSTANCE;
}
/**
* Get the score.
*
* @return The score.
*/
public int getScore() {
return this.score;
}
/**
* Increase the score by a specified amount.
*
* @param inc The amount to increase the score by.
* @pre. inc >= 0
*/
public void increase(int inc) {
this.score += inc;
}
/**
* Decrease the score by a specified amount.
*
* @param dec The amount to decrease the score by.
* @pre. dec >= 0
*/
public void decrease(int dec) {
this.score -= dec;
}
public static void main(String[] args) {
GameScore s = GameScore.getInstance();
s.increase(5);
System.out.println(s.getScore());
GameScore t = GameScore.getInstance();
t.increase(5);
System.out.println(s.getScore());
}
}