|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvooga.engine.factory.LevelManager
public class LevelManager
This class takes care of different tasks like reading level names from a file,
making a Map of these level files and loading next level etc. It loads
the levels when they are needed. However, if all the levels need to be loaded
at the beginning of the game , then a call to getAllPlayFields()
method would return all the level Playfields at once, in a list according to the
order in which they need to be loaded.
An example of how this could be used in a game is as follows:
public void initResources() {
LevelManager levelManager = new LevelManager(this);
String levelFilesDirectory = Resources.getString("levelFilesDirectory");
String levelNamesFile = Resources.getString("levelNamesFile");
levelManager.makeLevels(levelFilesDirectory,levelNamesFile);
PlayField levelPlayField = levelManager.loadFirstLevel();
playState = new PlayState(this, levelPlayField);
}
The String "levelFilesDirectory" in resources.xml file should be mapped to something
like "src/vooga/games/asteroids/resources/levels" where asteroids would be replaced by
your game's name, and here it is assumed that your levelNames file as well as all your
level xml files are stored in a package called levels in your resources package.
To load levels one by one, i.e., as they are needed, the following code can be used:
public void update(long elapsedTime){
if(levelcomplete condition){
playfield.clearPlayField();
playfield=levelManager.loadNextLevel();
}
}
To get all the playfields at the beginning of the game, this method call would be useful:
levelManager.getAllPlayFields();
Constructor Summary | |
---|---|
LevelManager(Game currentgame)
|
|
LevelManager(Game currentgame,
LevelParser parser)
|
Method Summary | |
---|---|
java.util.Collection<PlayField> |
getAllPlayFields()
This method is used to get a list of all the playfields for the current game. |
int |
getCurrentLevel()
Returns an integer representing the curremt level number. |
java.lang.String |
getCurrentLevelName()
Returns the name of the current level. |
int |
getNumLevels()
|
PlayField |
loadFirstLevel()
Returns the PlayField for the first level. |
PlayField |
loadNextLevel()
Returns the PlayField for the next level to be loaded. |
java.util.Map<java.lang.String,java.lang.String> |
makeLevels(java.lang.String levelPath,
java.lang.String levelNamesFile)
This method reads in from a File containing the names of different levels and returns a Map where level numbers are mapped to the names of the different level xml files. |
PlayField |
skipToLevel(int levelIndex)
Skips to and loads the specified level. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LevelManager(Game currentgame)
public LevelManager(Game currentgame, LevelParser parser)
Method Detail |
---|
public PlayField loadFirstLevel()
public java.util.Map<java.lang.String,java.lang.String> makeLevels(java.lang.String levelPath, java.lang.String levelNamesFile)
levelPath
- - directory path where all level files are storedlevelNamesFile
- - name of the File which specifies the names of the
levels in the order in which they are to be loaded
public java.util.Collection<PlayField> getAllPlayFields()
public PlayField loadNextLevel()
public PlayField skipToLevel(int levelIndex)
levelIndex
-
public int getCurrentLevel()
public int getNumLevels()
public java.lang.String getCurrentLevelName()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |