|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectJTP.LevelSet
public class LevelSet
Deals with handling and storage of a collection of levels.
Constructor Summary | |
---|---|
LevelSet(String name,
int levelWidth,
int levelHeight,
int tileHeightLimit)
Constructs a new single-player LevelSet instance with the
given attributes. |
|
LevelSet(String name,
int levelWidth,
int levelHeight,
int tileHeightLimit,
boolean twoPlayer)
Constructs a LevelSet instance with the given attributes. |
Method Summary | |
---|---|
Level |
addLevel()
Creates and adds a new level to this LevelSet . |
void |
addLevel(Level l)
Adds a new level manually. |
int[] |
getInvalidLevelIndices()
Returns indices of invalid levels in this LevelSet . |
Level |
getLevel(int index)
Provides direct access to a level in this set. |
String |
getName()
Returns name of this LevelSet . |
int |
getSize()
Returns number of levels stored in this LevelSet . |
boolean |
isTwoPlayer()
Returns whether this is a two-player LevelSet . |
static LevelSet |
load(String filename)
Loads a LevelSet from a file. |
static LevelSet |
load(URL location)
Loads a LevelSet from the given location. |
void |
purgeEmptyLevels()
Removes all empty levels from this LevelSet |
void |
purgeInvalidLevels()
Removes all invalid and empty levels from this LevelSet . |
boolean |
readOnly()
Returns whether the level can be saved or not. |
void |
removeLevel(int index)
Removes a level from this LevelSet . |
static boolean |
saveToDisk(LevelSet levelSet,
String filename,
boolean overwrite)
Writes the specified LevelSet to a file. |
void |
setName(String name)
Changes the name of this LevelSet . |
boolean |
swapLevel(int index)
Swaps specified level with next one. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LevelSet(String name, int levelWidth, int levelHeight, int tileHeightLimit) throws IllegalArgumentException, NullPointerException
LevelSet
instance with the
given attributes.
name
- name of the levelsetlevelWidth
- width in tiles of levels stored in this setlevelHeight
- height in tiles of levels stored in this settileHeightLimit
- maximum height of any one pile of tiles
IllegalArgumentException
- if any of the following are satisfied:
levelWidth
< 2levelHeight
< 2tileHeightLimit
< 1NullPointerException
- if name
is null
public LevelSet(String name, int levelWidth, int levelHeight, int tileHeightLimit, boolean twoPlayer) throws IllegalArgumentException, NullPointerException
LevelSet
instance with the given attributes.
name
- name of the levelsetlevelWidth
- width in tiles of levels stored in this setlevelHeight
- height in tiles of levels stored in this settileHeightLimit
- maximum height of any one pile of tilestwoPlayer
- defines whether this will be a single or two-player
levelset
IllegalArgumentException
- if any of the following are satisfied:
levelWidth
< 2levelHeight
< 2tileHeightLimit
< 1NullPointerException
- if name
is null
Method Detail |
---|
public int getSize()
LevelSet
.
public String getName()
LevelSet
.
public void setName(String name) throws NullPointerException
LevelSet
.
name
- new name for this set
NullPointerException
- if name
is null
public boolean isTwoPlayer()
LevelSet
.
true
if this is a two-player setpublic Level addLevel()
LevelSet
.
Level
public void addLevel(Level l) throws NullPointerException
l
- the Level
to add
NullPointerException
- if l
is null
public void removeLevel(int index) throws IndexOutOfBoundsException
LevelSet
.
index
- position of the level to be removed in this set
IndexOutOfBoundsException
- if index
is invalidpublic boolean swapLevel(int index) throws IndexOutOfBoundsException
index
- position of the level to be swapped with its right neighbour
false
if the level could not be swapped (i.e. if
trying to swap last level as there is no next level), true
otherwise
IndexOutOfBoundsException
- if index
is invalidpublic Level getLevel(int index) throws IndexOutOfBoundsException
index
- position of th level to retrieve
Level
IndexOutOfBoundsException
- if index
is invalidpublic void purgeInvalidLevels()
LevelSet
.
Note: Validity of a level is defined in the following method:
Level.isValid()
public void purgeEmptyLevels()
LevelSet
public int[] getInvalidLevelIndices()
LevelSet
.
Note: Empty levels are not counted as invalid.
null
if all levels
are validpublic boolean readOnly()
true
if the level can be saved.public static boolean saveToDisk(LevelSet levelSet, String filename, boolean overwrite) throws IOException
LevelSet
to a file.
Note: If the level is read-only (see readOnly
then the
level will definitely not be saved.
levelSet
- the set to savefilename
- name (and path) of the file to save the set inoverwrite
- specifies whether to force the file to be overwritten if
it already exists
false
ifoverwrite
parameter is
not setIOException
- if the write to disk attempt was not successfulpublic static LevelSet load(URL location) throws ClassNotFoundException, IOException, NullPointerException
LevelSet
from the given location.
Note: This method can be used to load a set from:
location
- full link to location of file from which to load the set
LevelSet
ClassNotFoundException
- if the file does not contain a
LevelSet
(or wrong LevelSet
format revision)
IOException
- if the read from file attempt was not successful
NullPointerException
- if location
is null
public static LevelSet load(String filename) throws ClassNotFoundException, NullPointerException, IOException
LevelSet
from a file.
filename
- name (and path) of the file to load the set from
LevelSet
ClassNotFoundException
- if the file does not contain a
LevelSet
(or wrong LevelSet
format revision)
IOException
- if the read from file attempt was not successful
NullPointerException
- if filename
is null
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |