JTP
Class ProgressHandler

java.lang.Object
  extended by JTP.ProgressHandler

public class ProgressHandler
extends Object

Provides methods for storing highscore and progress data to disk and handling of area unlocking.

Author:
V.Termanis

Field Summary
static int EDITOR
          Progress milestone: Editor
static int FAILED_TO_SAVE
          Indicates progress data could not be saved.
static int LOAD_CUSTOM
          Progress milestone: Loading of custom levelsets
static int ONEP_CHALLENGE
          Progress milestone: Single player challenge mode
static int SAVED
          Indicates progress data was saved.
static int TWOP_CHALLENGE
          Progress milestone: Two player challenge mode
static int TWOP_COOP
          Progress milestone: Two player cooperative mode
static int TWOP_VS
          Progress milestone: Two player versus mode
static int TWOP_VS_ALT
          Progress milestone: Two player versus alternate mode
static int UNLOCKED
          Indivates progress data was saved and an area unlocked.
 
Constructor Summary
ProgressHandler()
           
 
Method Summary
static boolean areaUnlocked(int type)
          Checks whether a particular area has been unlocked.
static int getAreaUnlockPoint(int type)
          Returns level which unlocks a certain area.
static String getProgressFilePath()
          Returns location of progress file.
static int getReachedLevel(boolean coop)
          Returns which level has been reached.
static String getRequestMessage(int type, boolean inGame)
          Creates message informing player which level they have to beat to unlock a particular area.
static String getUnlockMessage(int levelIndex)
          Returns string representation of unlocked area.
static int levelWillUnlockMode(int levelIndex)
          Returns whether a particular level will unlock an area
static Progress loadProgress()
          Loads progress data from disk.
static boolean progressMade(boolean coop)
          Checks whether any progress has been made in a levelset.
static void saveProgress(Progress progress)
          Saves progress data to disk.
static void setProgressFilePath(String path)
          Sets location of progress file.
static int setReachedLevel(int levelNumber, boolean coop)
          Updates progress made in levelset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FAILED_TO_SAVE

public static final int FAILED_TO_SAVE
Indicates progress data could not be saved.

See Also:
Constant Field Values

SAVED

public static final int SAVED
Indicates progress data was saved.

See Also:
Constant Field Values

UNLOCKED

public static final int UNLOCKED
Indivates progress data was saved and an area unlocked.

See Also:
Constant Field Values

ONEP_CHALLENGE

public static final int ONEP_CHALLENGE
Progress milestone: Single player challenge mode

See Also:
Constant Field Values

TWOP_COOP

public static final int TWOP_COOP
Progress milestone: Two player cooperative mode

See Also:
Constant Field Values

TWOP_CHALLENGE

public static final int TWOP_CHALLENGE
Progress milestone: Two player challenge mode

See Also:
Constant Field Values

TWOP_VS

public static final int TWOP_VS
Progress milestone: Two player versus mode

See Also:
Constant Field Values

TWOP_VS_ALT

public static final int TWOP_VS_ALT
Progress milestone: Two player versus alternate mode

See Also:
Constant Field Values

LOAD_CUSTOM

public static final int LOAD_CUSTOM
Progress milestone: Loading of custom levelsets

See Also:
Constant Field Values

EDITOR

public static final int EDITOR
Progress milestone: Editor

See Also:
Constant Field Values
Constructor Detail

ProgressHandler

public ProgressHandler()
Method Detail

setProgressFilePath

public static void setProgressFilePath(String path)
                                throws NullPointerException
Sets location of progress file. Note: No check is performed on whether this is a valid location, i.e. whether the file can be read from / written to.

Parameters:
path - the relative or absolute path (and name) of the progress file
Throws:
NullPointerException - if path is null

getProgressFilePath

public static String getProgressFilePath()
Returns location of progress file.

Returns:
the relative or absolute path (and name) of the progress file

getUnlockMessage

public static String getUnlockMessage(int levelIndex)
Returns string representation of unlocked area.

Parameters:
levelIndex - level currently unlocked.
Returns:
string representation of unlocked area of null if completing the given level did not unlock a new area.

levelWillUnlockMode

public static int levelWillUnlockMode(int levelIndex)
Returns whether a particular level will unlock an area

Parameters:
levelIndex - the level to check against
Returns:
the area code if this area has not been unlocked or -1 otherwise.

getAreaUnlockPoint

public static int getAreaUnlockPoint(int type)
Returns level which unlocks a certain area.

Parameters:
type - one of ONEP_CHALLENGE, TWOP_COOP, TWOP_CHALLENGE, TWOP_VS, TWOP_VS_ALT or EDITOR.
Returns:
the level which unlocks the area.
Throws:
IllegalArgumentException - if type is not a valid area.

getRequestMessage

public static String getRequestMessage(int type,
                                       boolean inGame)
Creates message informing player which level they have to beat to unlock a particular area.

Parameters:
type - one of ONEP_CHALLENGE, TWOP_COOP, TWOP_CHALLENGE, TWOP_VS, TWOP_VS_ALT or EDITOR.
Returns:
the constructed message
Throws:
IllegalArgumentException - if type is not a valid area.

areaUnlocked

public static boolean areaUnlocked(int type)
                            throws IllegalArgumentException
Checks whether a particular area has been unlocked.

Parameters:
type - one of ONEP_CHALLENGE, TWOP_COOP, TWOP_CHALLENGE, TWOP_VS, TWOP_VS_ALT or EDITOR.
Returns:
the constructed message
Throws:
IllegalArgumentException - if type is not a valid area.

progressMade

public static boolean progressMade(boolean coop)
Checks whether any progress has been made in a levelset.

Parameters:
coop - either Progress.SINGLE or Progress.COOP.
Returns:
true if at least one level has been completed.

getReachedLevel

public static int getReachedLevel(boolean coop)
Returns which level has been reached. Note: In development mode this will always return Integer.MAX_VALUE.

Parameters:
coop - either Progress.SINGLE or Progress.COOP.
Returns:
  • the reached level
  • 0 if no progress has been made, or
  • -1 if progress data could not be loaded from disk.

setReachedLevel

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

Parameters:
levelNumber - the level reached.
coop - either Progress.SINGLE or Progress.COOP.
Returns:
  • SAVED if the updated progress was saved to disk
  • UNLOCKED if progress was saved and a new are has been unlocked, or
  • FAILED_TO_SAVE if there was a problem in writing the progress information to disk.
Throws:
IllegalArgumentException - if levelNumber < 0.

loadProgress

public static Progress loadProgress()
Loads progress data from disk.

Returns:
loaded progress or a new instance of Progress if loading from disk failed.

saveProgress

public static void saveProgress(Progress progress)
                         throws IOException,
                                NullPointerException
Saves progress data to disk.

Parameters:
progress - the progress information to save.
Throws:
IOException - if there was a problem in writing the progress information to disk
NullPointerException - if progress is null