-
Notifications
You must be signed in to change notification settings - Fork 4
LevelWaves
The LevelWaves
class handles the collection of waves that are associated with a particular level. It can be used to retrieve waves, create new waves or to retrieve other relevant details, like the spawnDelay
or mobIndex
, for example.
This class is called in WaveFactory
and creates the List of waves to be spawned, as defined by the chosen level. An implementation of this is shown below.
LevelWaves level = createLevel(difficulty, maxWaves, chosenLevel);
level.addWave(new WaveClass(mobs));
There are a range of getters/setters that can be used to configure further details of the level. Some of the key methods are explained below.
This method takes a HashMap as a parameter which defines the mobs and their quantity for a wave. For example, a HashMap could contain {(Xeno, 5), (SplittingXeno, 4)}
, which indicates a wave will contain 5 Xeno mobs and 4 Splitting Xeno mobs. The wave is added to an internal array of waves within LevelWaves
, which can be accessed via getWave()
.
This method allows access to the wave array via an index. Waves are stored in the order they should be spawned.
This method allows for the spawning of an individual wave. Each mob in the wave spawns based on a timer, with there being a modifiable spawnDelay
between each mob. A random lane is chosen for each mob.
This method sets the currently active wave based on an index parameter.
Returns the number of waves in the level.
Tests for this class have been created in LevelWavesTest
.
Initialises a mock LevelWaves
, Wave
and GameTime
, which are used in later tests when specifying specific behaviour.
Tests that when a wave is added to a level, the number waves increases accordingly. This uses the mock object to get the initial wave count, adds a new wave, and verifies that the number of waves has increased using the getNumWaves()
method.
Tests that a spawnWave()
call results in the correct behaviour by first setting the index of the mock wave, then calling the spawnWave()
method. After this call, the test asserts that the getWave()
call to WaveClass
returns a value greater than 0 (i.e more than 0 enemies will spawn), and that the array holding the mob information is not empty.
Mocks a call to the LevelWaves startTime
by setting the return to a fixed value, then asserts that a call to getStartTime()
returns the correct value.