vooga.engine.factory
Class LevelManager

java.lang.Object
  extended by vooga.engine.factory.LevelManager
Direct Known Subclasses:
GalaxyLevelManager

public class LevelManager
extends java.lang.Object

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

LevelManager

public LevelManager(Game currentgame)

LevelManager

public LevelManager(Game currentgame,
                    LevelParser parser)
Method Detail

loadFirstLevel

public PlayField loadFirstLevel()
Returns the PlayField for the first level.

Returns:
PlayField for the firt level

makeLevels

public 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.

Parameters:
levelPath - - directory path where all level files are stored
levelNamesFile - - name of the File which specifies the names of the levels in the order in which they are to be loaded
Returns:
a Map of level numbers to level files names

getAllPlayFields

public java.util.Collection<PlayField> getAllPlayFields()
This method is used to get a list of all the playfields for the current game. Every playfield is associated with one level. The returned list contains the playfields in the order in which they are to be loaded. A call to this method would be useful in cases where all the playfields / levels need to be loaded at the beginning of the game.

Returns:
collection of Playfields listed in the order in which they are to be loaded

loadNextLevel

public PlayField loadNextLevel()
Returns the PlayField for the next level to be loaded.

Returns:
PlayField for next level

skipToLevel

public PlayField skipToLevel(int levelIndex)
Skips to and loads the specified level.

Parameters:
levelIndex -
Returns:
Playfield for the specified level

getCurrentLevel

public int getCurrentLevel()
Returns an integer representing the curremt level number.

Returns:
myCurrentLevel - current level number

getNumLevels

public int getNumLevels()

getCurrentLevelName

public java.lang.String getCurrentLevelName()
Returns the name of the current level.

Returns:
Name of the level file for the current level