Merge Score and Credits into PlayerSession, avoid directly setting the values.

This commit is contained in:
JPT committed 2014-11-28 20:27:55 +01:00
1 parent 96f03c5cda
commit 308ee0550f
9 files changed
+116 -129

No files matched your search

@@ -0,0 +1,91 @@
package de.teamteamteam.spacescooter.brain;
/**
* This class is responsible for keeping track of all the data a player session
* usually contains, such as earned score points, earned credits, activated ship upgrades
* and more.
*/
public class PlayerSession {
/**
* The players current score.
*/
private static int score;
/**
* The players current amount of credits.
*/
private static int credits;
/**
* Private constructor, this class will never be instantiated.
*/
private PlayerSession() {}
/**
* Get the current amount of credits the player has.
*/
public static int getCredits() {
return PlayerSession.credits;
}
/**
* Add a number of credits to the players credits.
*/
public static void addCredits(int credits) {
PlayerSession.credits += credits;
}
/**
* Remove a number of credits from the players credits.
* This is capped at zero.
*/
public static void removeCredits(int credits) {
PlayerSession.credits -= credits;
if(PlayerSession.credits < 0) {
PlayerSession.credits = 0;
}
}
/**
* Get the current player score.
*/
public static int getScore() {
return PlayerSession.score;
}
/**
* Add a number of points to the players score.
* There is a maximum of X points to reach, score is capped then.
*/
public static void addScore(int points) {
PlayerSession.score += points;
if(PlayerSession.score > GameConfig.maximumPlayerScore) {
PlayerSession.score = GameConfig.maximumPlayerScore;
}
}
/**
* Remove a number of points from the players score.
* This is capped at zero.
*/
public static void removeScore(int points) {
PlayerSession.score -= points;
if(PlayerSession.score < 0) {
PlayerSession.score = 0;
}
}
/**
* This will reset all data from the players session.
* Used to initialize the session at the beginning of the game or
* after the player went game over and entered his name for the highscore.
*/
public static void reset() {
PlayerSession.score = 0;
PlayerSession.credits = 0;
}
}