public class Level
extends java.lang.Object
Constructor and Description |
---|
Level(java.util.Random randGen,
java.lang.String level)
This constructor initializes a new Level object, so that the GameEngine
can begin calling its update() method to advance the game's play.
|
Modifier and Type | Method and Description |
---|---|
void |
createRandomLevel()
This method creates a random level consisting of a single Hero centered
in the middle of the screen, along with 6 randomly positioned Fires,
and 20 randomly positioned Pants.
|
java.lang.String |
getHUDMessage()
This method returns a string of text that will be displayed in the
upper left hand corner of the game window.
|
void |
loadLevel(java.lang.String level)
This method initializes the current game according to the Object location
descriptions within the level parameter.
|
static void |
main(java.lang.String[] args)
This method creates and runs a new GameEngine with its first Level.
|
java.lang.String |
update(int time)
The GameEngine calls this method repeatedly to update all of the objects
within your game, and to enforce all of the rules of your game.
|
public Level(java.util.Random randGen, java.lang.String level)
randGen
- is the only Random number generator that should be used
throughout this level, by the Level itself and all of the Objects within.level
- is a string that either contains the word "RANDOM", or the
contents of a level file that should be loaded and played.public java.lang.String update(int time)
time
- is the time in milliseconds that have elapsed since the last
time this method was called. This can be used to control the speed that
objects are moving within your game.public java.lang.String getHUDMessage()
public void createRandomLevel()
public void loadLevel(java.lang.String level)
level
- is a string containing the contents of a custom level file
that is read in by the GameEngine. The contents of this file are then
passed to Level through its Constructor, and then passed from there to
here when a custom level is loaded. You can see the text within these
level files by dragging them onto the code editing view in Eclipse, or
by printing out the contents of this level parameter. Try looking
through a few of the provided level files to see how they are formatted.
The first line is always the "ControlType: #" where # is either 1, 2, or
3. Subsequent lines describe an object TYPE, along with an X and Y
position, formatted as: "TYPE @ X, Y". This method should instantiate
and initialize a new object of the correct type and at the correct
position for each such line in the level String.public static void main(java.lang.String[] args)
args
- is the sequence of custom level files to play through.