JTP
Class Progress

java.lang.Object
  extended by JTP.Progress
All Implemented Interfaces:
Serializable

public class Progress
extends Object
implements Serializable

Keeps track of highscores, levels reached and areas unlocked.

Author:
V.Termanis
See Also:
Serialized Form

Field Summary
static boolean COOP
          Cooperative.
static int HIGH_SCORE_COUNT
          Number of entries in each highscore table.
static boolean SINGLE
          Single player.
 
Constructor Summary
Progress()
          Constructs a new Progress instance.
 
Method Summary
 boolean addHighScore(boolean coop, int score, String name)
          Adds score to the highscore table.
 String getName(boolean coop, int index)
          Retrieves name associated with a score from the highscore table.
 int getReachedLevel(boolean coop)
          Returns progress made in the levelset.
 int getScore(boolean coop, int index)
          Retrieves score from the highscore table.
 int isHighScoreWhere(boolean coop, int score)
          Checks whether the given score can go in the highscore table.
 void setReachedLevel(int levelNumber, boolean coop)
          Updates progress made in the levelset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HIGH_SCORE_COUNT

public static final int HIGH_SCORE_COUNT
Number of entries in each highscore table.

See Also:
Constant Field Values

SINGLE

public static final boolean SINGLE
Single player.

See Also:
Constant Field Values

COOP

public static final boolean COOP
Cooperative.

See Also:
Constant Field Values
Constructor Detail

Progress

public Progress()
Constructs a new Progress instance.

Method Detail

getReachedLevel

public int getReachedLevel(boolean coop)
Returns progress made in the levelset.

Parameters:
coop - specifies which levelset - can be either SINGLE or COOP.
Returns:
level reached

setReachedLevel

public void setReachedLevel(int levelNumber,
                            boolean coop)
                     throws IllegalArgumentException
Updates progress made in the levelset. Note: Reached level will only be updated if it is greater than currently stored value.

Parameters:
levelNumber - level reached
coop - specifies which levelset - can be either SINGLE or COOP.
Throws:
IllegalArgumentException - if levelNumber < 0.

isHighScoreWhere

public int isHighScoreWhere(boolean coop,
                            int score)
Checks whether the given score can go in the highscore table.

Parameters:
coop - specifies which levelset - can be either SINGLE or COOP.
score - the score.
Returns:
position in the highscore table the score will take or -1 if the score is not high enough.

addHighScore

public boolean addHighScore(boolean coop,
                            int score,
                            String name)
                     throws NullPointerException,
                            IllegalArgumentException
Adds score to the highscore table.

Parameters:
coop - specifies which levelset - can be either SINGLE or COOP.
score - the score.
Returns:
true if the score was added or false if score is not a highscore.
Throws:
NullPointerException - if name is null.
IllegalArgumentException - if score < 1.

getScore

public int getScore(boolean coop,
                    int index)
             throws ArrayIndexOutOfBoundsException
Retrieves score from the highscore table.

Parameters:
coop - specifies which levelset - can be either SINGLE or COOP.
index - in highscore list of wanted score.
Returns:
the score
Throws:
ArrayIndexOutOfBoundsException - if index < 0 or index >= HIGH_SCORE_COUNT.

getName

public String getName(boolean coop,
                      int index)
               throws ArrayIndexOutOfBoundsException
Retrieves name associated with a score from the highscore table.

Parameters:
coop - specifies which levelset - can be either SINGLE or COOP.
index - in highscore list of wanted score.
Returns:
the score
Throws:
ArrayIndexOutOfBoundsException - if index < 0 or index >= HIGH_SCORE_COUNT.