Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team 4 waves #221

Merged
merged 9 commits into from
Oct 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ public LevelWaves(int spawnDelay) {

long currentTime = ServiceLocator.getTimeSource().getTime();
// Setting the timestamp for when the next mobs will spawn.
// Currently, the delay of mobs spawning after wave start
// is hardcoded but will fix in the next push.
ServiceLocator.getWaveService().setNextWaveTime(currentTime + 10000);
// Currently, the delay of mobs spawning after wave start.
ServiceLocator.getWaveService().setNextWaveTime(currentTime + (spawnDelay * 1000));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public WaveClass(HashMap<String, int[]> entities) {
* Get the entities that are part of this wave and randomise the order they are spawned
* @return mobs for the wave in form of (mob name, mob health)
*/
private List<Tuple> entitiesToWave() {

public List<Tuple> entitiesToWave() {
List<Tuple> enemies = new ArrayList<>();
for (Map.Entry<String, int[]> set : entities.entrySet()) {
for (int i = 0; i < set.getValue()[0]; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public void update() {
long currentTime = ServiceLocator.getTimeSource().getTime();
// Setting the timestamp for when the next mobs will spawn.
// Currently, the delay of mobs spawning after wave start
// is hardcoded but will fix in the next push.
ServiceLocator.getWaveService().setNextWaveTime(currentTime + 10000);
int spawnDelay = ServiceLocator.getWaveService().getSpawnDelay();
ServiceLocator.getWaveService().setNextWaveTime(currentTime + (spawnDelay * 1000));

// Check if level has been completed - no more waves remaining
if (currentWaveIndex == this.level.getNumWaves()) {
Expand All @@ -120,10 +120,10 @@ public void update() {
}

} else {
// logger.info("{} enemies remaining in wave {}", ServiceLocator.getWaveService().getEnemyCount(), currentWaveIndex);
// logger.info("WAVE SERVICE NUMBER: Wave Number {}",ServiceLocator.getWaveService().getWaveCount());
// logger.info("NEXT WAVE AT {}", ServiceLocator.getWaveService().getNextWaveTime());
// logger.info("TIME IS {}", ServiceLocator.getTimeSource().getTime());
//logger.info("{} enemies remaining in wave {}", ServiceLocator.getWaveService().getEnemyCount(), currentWaveIndex);
//logger.info("WAVE SERVICE NUMBER: Wave Number {}",ServiceLocator.getWaveService().getWaveCount());
//logger.info("NEXT WAVE AT {}", ServiceLocator.getWaveService().getNextWaveTime());
//logger.info("TIME IS {}", ServiceLocator.getTimeSource().getTime());
if (waveInProgress) {
this.level.spawnWave();
}
Expand All @@ -137,4 +137,12 @@ public void update() {
public boolean isWaveInProgress() {
return waveInProgress;
}

/**
* Gets the current wave index
* @return current wave index
*/
public int getCurrentWaveIndex() {
return currentWaveIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.csse3200.game.components.tasks.waves.WaveTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.screens.GameLevelData;
import com.csse3200.game.services.ServiceLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -97,10 +98,16 @@ public static LevelWaves createLevel(int maxDiff, int maxWaves, int chosenLevel)
String boss1 = "IceBoss";
// String boss1 = "PatrickBoss";
String boss2 = "PatrickBoss";
// String boss3 = "IceBoss";
//TODO change this to a fire boss in sprint 4
String boss3 = "FireBoss";
LevelWaves level = new LevelWaves(5);
//String boss3 = "IceBoss";

String boss3 = "FireBoss";

int spawnDelay = 5;

// Create new level entity with spawn delay of 5 seconds
LevelWaves level = new LevelWaves(spawnDelay);
// Tell the waveService what the spawn delay for levels will be (for UI team).
ServiceLocator.getWaveService().setSpawnDelay(spawnDelay);

ArrayList<String> possibleMobs;

Expand Down
16 changes: 15 additions & 1 deletion source/core/src/main/com/csse3200/game/services/WaveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class WaveService {
private long nextWaveTime;
private final UIElementsDisplay display;

private int spawnDelay;


/**
* Constructor for the Wave Service
Expand Down Expand Up @@ -122,7 +124,19 @@ public void setNextWaveTime(long nextWaveTime) {
}

/**
* Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed
* Sets the spawn delay between levels
* @param spawnDelay representing the spawnDelay between levels.
*/
public void setSpawnDelay(int spawnDelay) {this.spawnDelay = spawnDelay;}

/**
* Returns the spawn delay between levels
* @return (int) The spawn delay between levels.
*/
public int getSpawnDelay() {return this.spawnDelay;}


/* Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed
* for this instance of the display.
* @return the updating instance of UIElementsDisplay
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.csse3200.game.components.tasks.waves;

import com.csse3200.game.components.tasks.waves.LevelWaves;
import com.csse3200.game.components.tasks.waves.WaveClass;
import com.csse3200.game.entities.factories.WaveFactory;
import com.csse3200.game.extensions.GameExtension;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -10,30 +13,50 @@
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

import static org.mockito.Mockito.when;

@Disabled

@ExtendWith(GameExtension.class)
@ExtendWith(MockitoExtension.class)
class LevelWavesTest {

LevelWaves levelWaves;
WaveClass wave;
ServiceLocator serviceLocator;
GameTime gameTime;

@BeforeEach
void setUp() {
levelWaves = (LevelWaves) WaveFactory.createWaves();
levelWaves = mock(LevelWaves.class);
wave = mock(WaveClass.class);
gameTime = mock(GameTime.class);
}

@Test
public void testAddWave() {
when(levelWaves.getNumWaves()).thenReturn(1);
int size = levelWaves.getNumWaves();
levelWaves.addWave(wave);
assertEquals(3, levelWaves.waves.size());
assertEquals(size + 1, levelWaves.getNumWaves());
}

@Test
public void testSpawnWaveStart() {
public void testSpawnWave() {
levelWaves.setWaveIndex(1);
levelWaves.spawnWave();
WaveClass thisWave = levelWaves.getWave(levelWaves.getWaveIndex());
assertTrue(thisWave.getSize() > 0);
assertTrue(!thisWave.getMobs().isEmpty());
}

@Test
public void testGetStartTime() {
when(levelWaves.getStartTime()).thenReturn(1000L);
assertEquals(1000L, levelWaves.getStartTime());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
package com.csse3200.game.components.tasks.waves;


import com.csse3200.game.components.tasks.waves.WaveClass;
import com.csse3200.game.extensions.GameExtension;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.HashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Disabled;

@ExtendWith(GameExtension.class)
@ExtendWith(MockitoExtension.class)

@Disabled
class WaveClassTest {

HashMap<String, int[]> waveContents;
WaveClass waveClass;
@BeforeEach
void setUp() {
waveContents = new HashMap<>();
waveContents.put("Xeno", new int[]{2, 20});
waveContents.put("DodgingDragon", new int[]{3, 40});
waveContents.put("SplittingXeno", new int[]{5, 60});
waveContents.put("DeflectXeno", new int[]{7, 80});
waveClass = new WaveClass(waveContents);
}

@Test
public void testGetMobs() {
List<Tuple> enemies = waveClass.getMobs();
assertTrue(enemies.contains("Xeno")
&& enemies.contains("DodgingDragon")
&& enemies.contains("SplittingXeno")
&& enemies.contains("DeflectXeno"));
}

@Test
public void testGetSize() {
int size = waveClass.getSize();
assertEquals(17, size);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.csse3200.game.components.tasks.waves;

import com.badlogic.gdx.audio.Sound;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.ai.tasks.Task;
import com.csse3200.game.areas.ForestGameArea;
import com.csse3200.game.areas.terrain.TerrainFactory;
import com.csse3200.game.components.tasks.DroidCombatTask;
import com.csse3200.game.components.tasks.waves.LevelWaves;
import com.csse3200.game.components.tasks.waves.WaveTask;
import com.csse3200.game.extensions.GameExtension;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ResourceService;
Expand Down Expand Up @@ -52,10 +56,34 @@ public void testGetPriority() {
}

@Test
public void testStartWave() {
public void testStartFirstWave() {
waveTask.start();
assertEquals(1, waveTask.getPriority());
assertEquals(10, waveTask.getPriority());
assertTrue(waveTask.isWaveInProgress());
assertEquals(1, waveTask.getCurrentWaveIndex());
}

@Test
public void testIsWaveInProgress() {
waveTask.start();
assertTrue(waveTask.isWaveInProgress());
}

@Test
public void testUpdateOnEmptyWaveAndNoNextWave() {
waveTask.start();
ServiceLocator.getWaveService().setEnemyCount(0);
waveTask.update();
assertTrue(ServiceLocator.getWaveService().isLevelCompleted());
}

@Test
public void testUpdateOnEmptyWaveAndNextWave() {
waveTask.start();
int waveNumber = waveTask.getCurrentWaveIndex();
ServiceLocator.getWaveService().setEnemyCount(0);
waveTask.update();
assertTrue(waveNumber + 1 == waveTask.getCurrentWaveIndex());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.csse3200.game.entities.factories;

import com.csse3200.game.components.tasks.waves.LevelWaves;
import com.badlogic.gdx.assets.AssetManager;
import com.csse3200.game.components.tasks.waves.LevelWaves;
import com.csse3200.game.components.tasks.waves.WaveClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.csse3200.game.services;

import com.badlogic.gdx.audio.Sound;
import com.csse3200.game.areas.ForestGameArea;
import com.csse3200.game.components.tasks.waves.LevelWaves;
import com.csse3200.game.components.tasks.waves.WaveTask;
import com.csse3200.game.extensions.GameExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtendWith;

import com.csse3200.game.entities.EntityService;
import com.csse3200.game.extensions.GameExtension;
import com.csse3200.game.physics.PhysicsService;
import com.csse3200.game.rendering.RenderService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;

@Disabled
@ExtendWith(GameExtension.class)
public class WaveServiceTest {

WaveTask waveTask;
ResourceService resourceService;
LevelWaves level;

WaveService waveService;
@BeforeEach
void setUp() {
resourceService = ServiceLocator.getResourceService();
waveService = ServiceLocator.getWaveService();
GameTime globalTime = mock(GameTime.class);
level = mock(LevelWaves.class);
ServiceLocator.registerTimeSource(globalTime);
waveTask = new WaveTask();
String[] sounds = waveTask.getSounds();
resourceService.getAsset(sounds[0], Sound.class);
resourceService.getAsset(sounds[1], Sound.class);
}

@Test
void shouldSetNextWaveTime() {

waveTask.start();
ServiceLocator.getWaveService().setEnemyCount(0);
waveTask.update();

assertTrue(ServiceLocator.getWaveService().getNextWaveTime() > 0);

}

}
Loading