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 - Final Code Smell Fixes & New Tests for WaveService Added. #298

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public static LevelWaves createLevel(int chosenLevel) {
int bossHealth;
int minMobs;
// Base health of the bosses
int LVL1_BOSS_BASE_HEALTH = 500;
int LVL2_BOSS_BASE_HEALTH = 1000;
int LVL3_BOSS_BASE_HEALTH = 2000;
final int LVL1_BOSS_BASE_HEALTH = 500;
final int LVL2_BOSS_BASE_HEALTH = 1000;
final int LVL3_BOSS_BASE_HEALTH = 2000;

switch (chosenLevel) {
case 2:
Expand All @@ -155,7 +155,6 @@ public static LevelWaves createLevel(int chosenLevel) {
break;
}

// int totalMobs = 0;
// Create mxWaves number of waves with mob stats increasing
int atWave = 1;
for (ArrayList<String> wave : possibleMobs) {
Expand All @@ -171,26 +170,23 @@ public static LevelWaves createLevel(int chosenLevel) {
// Calculate the number of mobs for the wave
if (leftToSort == 0) {
num = minMobs - currentMobs;
System.out.println(num + " for " + mob + " at wave " + atWave);
} else {
num = rand.nextInt(minMobs - currentMobs - (2 * leftToSort) - 2) + 2;
System.out.println(num + " for " + mob + " at wave " + atWave);
currentMobs += num;
}

// Calculate the health
int RANGE_BASE_HEALTH = 60;
final int RANGE_BASE_HEALTH = 60;
int health = RANGE_BASE_HEALTH;
if (MELEE_MOBS.contains(mob)) {
// The base health for the different mobs
int MELEE_BASE_HEALTH = 80;
final int MELEE_BASE_HEALTH = 80;
health = MELEE_BASE_HEALTH;
}
int[] mobStats = {num, health + (atWave * chosenLevel)};
mobs.put(mob, mobStats);

leftToSort --;
// totalMobs += num;
}
minMobs ++;
level.addWave(new WaveClass(mobs));
Expand All @@ -200,9 +196,7 @@ public static LevelWaves createLevel(int chosenLevel) {
// Add boss wave
HashMap<String, int[]> bossMob = new HashMap<>();
bossMob.put(boss, new int[]{1, bossHealth});
// totalMobs ++;

// ServiceLocator.getWaveService().setTotalMobs(totalMobs);
level.addWave(new WaveClass(bossMob));


Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,76 @@
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 com.csse3200.game.rendering.DebugRenderer;
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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.mockito.junit.jupiter.MockitoExtension;

@Disabled
@ExtendWith(GameExtension.class)
@ExtendWith(MockitoExtension.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);
GameTime gameTime = mock(GameTime.class);
ServiceLocator.registerTimeSource(gameTime);
ServiceLocator.registerPhysicsService(new PhysicsService());
RenderService render = new RenderService();
render.setDebug(mock(DebugRenderer.class));
ServiceLocator.registerRenderService(render);
ResourceService resourceService = mock(ResourceService.class);
ServiceLocator.registerResourceService(resourceService);
ServiceLocator.registerWaveService(new WaveService());
}

@Test
void testSetWaveCount() {
// setting the number of waves to be 5 will give you an index of 6 because the wave number
// goes from 1-6 instead of 0-5. Because players like to see "starting at level 1 not 0.
ServiceLocator.getWaveService().setWaveCount(5);
assertEquals(6, ServiceLocator.getWaveService().getWaveCount());
}

@Test
public void testSetLevelCompleted() {
ServiceLocator.getWaveService().setLevelCompleted();
assertTrue(ServiceLocator.getWaveService().isLevelCompleted());
}

@Test
void shouldSetNextWaveTime() {
void testSetNextLane() {
ServiceLocator.getWaveService().setNextLane(2);
assertEquals(2, ServiceLocator.getWaveService().getNextLane());
}

waveTask.start();
ServiceLocator.getWaveService().setEnemyCount(0);
waveTask.update();
@Test
void testToggleDelay() {
ServiceLocator.getWaveService().toggleDelay();
assertTrue(ServiceLocator.getWaveService().shouldSkip());
}

assertTrue(ServiceLocator.getWaveService().getNextWaveTime() > 0);
@Test
void testSetTotalMobs() {
ServiceLocator.getWaveService().setTotalMobs(100);
assertEquals(100, ServiceLocator.getWaveService().totalMobs());
assertEquals(100, ServiceLocator.getWaveService().remainingMobsForLevel());
}

@Test
void testToggleGamePaused() {
// the toggle game paused method should flip the
// gamePaused variable
// This is checked with an assertEquals test.
boolean gamePaused = ServiceLocator.getWaveService().getGamePaused();
ServiceLocator.getWaveService().toggleGamePause();
assertEquals(!gamePaused, ServiceLocator.getWaveService().getGamePaused());
}


}
Loading