Skip to content

WaveService

max9753 edited this page Oct 17, 2023 · 12 revisions

Introduction

The WaveService class is used to manage the number of mobs in a particular wave and determines when the level has been completed. It works in conjunction with the WaveTask class.

Usage

When a new WaveTask is created, the WaveService is automatically running alongside it. No additional calls of the class are required.

setEnemyCount()

The method takes an int value, which represents the number of mobs in the wave. When the class is initialised, the count is set to 0. In WaveTask, the number of enemies is set to be the size of the current wave.

getEnemyCount()

This method returns the number of enemies currently alive.

updateEnemyCount()

When an enemy is killed and disposed of, this method is called and decrements the number of mobs. It also links to the UI Display which shows the user the number of mobs remaining in the current wave. This can be seen in the Sequence Diagram below. Decrementing Mob Counter

setLevelCompleted()

This method sets a boolean value, levelCompleted to be true. This is called in WaveTask when the number of mobs is 0 and the wave index has reached the number of waves (i.e. there are no more waves to be spawned).

isLevelCompleted()

Returns true if the level has been completed, or false if there are still mobs or waves remaining.

getWaveCount()

Returns an int representing the current wave number.

setWaveCount()

This method takes an int and is used to set the current wave number in the service so that it can be accessed from elsewhere in elements such as UI.

getNextWaveTime()

This method returns a long timestamp of when the next mobs will spawn for the player. This will return a new value at the start of each wave and remain the same throughout the wave.

setNextWaveTime()

This method takes a long and sets the timestamp for when the next wave will be.

setSpawnDelay()

This method takes an int representing the number of seconds to delay spawning mobs between the end of one wave and the start of another.

getSpawnDelay()

This method returns an int representing the spawn delay, in seconds, between each level where the mobs spawn. It was decided to have this as a service member as it may be useful to have accessible for UI elements or settings etc. May be depreciated in future if better implemented elsewhere.

getDisplay()

Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed for this instance of the display.

toggleGamePause()

Toggles whether the game is paused or not, to keep track of how long the game is paused. When unpaused, offsets the NextWaveTime by however long the game has been paused.

totalMobs()

Retrieve the total number of mobs for the entire level.

Testing Plan

The most important members of WaveService currently have each have simple tests to check functionality. These members are pretty essential to the UI elements of the game and user experience and thus testing was incredibly important.

setUp() Test

This test sets up the WaveService and the services needed for it. Mocks several classes and registers needed services.

testSetWaveCount() Test

This test checks the functionality of the setter method of waveCount in the WaveService. This is very important for the wave display UI element on the players screen.

testSetLevelCompleted() Test

This test checks the functionality of letting the service know that the level is completed. This is also very important for gameplay as it is required for the game to end or the next level to start. That's why this methods functionality is tested.

testSetNextLane() Test

This test checks the functionality of the set next lane method which will let the player know, using UI elements, what lane a mob will spawn next in. It's an important part of gameplay and that's why this method has been tested.

testToggleDelay() Test

This test checks the functionality of the delay skipping part of the game. Players can choose to skip the delay at the start of each wave and that's what this method of the service is used for. It's importance is why we chose to test this method.

testSetTotalMobs() Test

This test checks the functionality of setting the total mobs that will be present in a wave. This is important for the UI elements of the game and letting a player know how many mobs will spawn in total in a wave.

testToggleGamePaused() Test

This test is important as it checks the functionality of pausing a wave when the game is paused itself. The service is used to pause the level when the game is paused. That's why this method was tested.

Clone this wiki locally