diff --git a/source/core/src/main/com/csse3200/game/rendering/CameraShaker.java b/source/core/src/main/com/csse3200/game/rendering/CameraShaker.java index 11359805d..cbfc432d1 100644 --- a/source/core/src/main/com/csse3200/game/rendering/CameraShaker.java +++ b/source/core/src/main/com/csse3200/game/rendering/CameraShaker.java @@ -184,4 +184,17 @@ private void checkParameters(float shakeRadius, float minimumShakeRadius, float this.minimumShakeRadius = minimumShakeRadius; this.radiusFallOffFactor = radiusFallOffFactor; } + + public float getShakeRadius() { + return shakeRadius; + } + + public float getMinimumRadius() { + return minimumShakeRadius; + } + + public float getFallOffFactor() { + return radiusFallOffFactor; + } + } \ No newline at end of file diff --git a/source/core/src/test/com/csse3200/game/areas/terrain/TerrainComponentTest.java b/source/core/src/test/com/csse3200/game/areas/terrain/TerrainComponentTest.java index 6cfdd45b5..68e13cdcc 100644 --- a/source/core/src/test/com/csse3200/game/areas/terrain/TerrainComponentTest.java +++ b/source/core/src/test/com/csse3200/game/areas/terrain/TerrainComponentTest.java @@ -24,11 +24,39 @@ import com.csse3200.game.services.CurrencyService; import com.csse3200.game.services.ResourceService; import com.csse3200.game.services.ServiceLocator; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(GameExtension.class) class TerrainComponentTest { + + private TerrainComponent component; + private TiledMapTile mockTile; + + @BeforeEach + public void setUp() { + component = makeComponent(TerrainOrientation.ORTHOGONAL, 1f); + + // Mock Gdx input to return specific mouse position + Gdx.input = mock(Input.class); + when(Gdx.input.getX()).thenReturn(2); + when(Gdx.input.getY()).thenReturn(4); + + + MapLayers mockLayers = mock(MapLayers.class); + when(component.getMap().getLayers()).thenReturn(mockLayers); + + TiledMapTileLayer mockTileLayer = mock(TiledMapTileLayer.class); + when(mockLayers.get(0)).thenReturn(mockTileLayer); + + TiledMapTileLayer.Cell mockCell = mock(TiledMapTileLayer.Cell.class); + when(mockTileLayer.getCell(2, 4)).thenReturn(mockCell); + + mockTile = mock(TiledMapTile.class); + when(mockCell.getTile()).thenReturn(mockTile); + + } @Test void shouldConvertPositionOrthogonal() { TerrainComponent component = makeComponent(TerrainOrientation.ORTHOGONAL, 3f); @@ -51,42 +79,44 @@ void shouldConvertPositionHexagonal() { } @Test - void shouldHighlightTileOnHover1() { - - TerrainComponent component = makeComponent(TerrainOrientation.ORTHOGONAL, 1f); - - // Mock Gdx input to return specific mouse position - Gdx.input = mock(Input.class); - when(Gdx.input.getX()).thenReturn(2); - when(Gdx.input.getY()).thenReturn(4); + void shouldHighlightTileGreenOnHover() { + Texture mockTexture = mock(Texture.class); + ServiceLocator.registerResourceService(mock(ResourceService.class)); - MapLayers mockLayers = mock(MapLayers.class); - when(component.getMap().getLayers()).thenReturn(mockLayers); + ServiceLocator.registerCurrencyService(mock(CurrencyService.class)); + when(ServiceLocator.getCurrencyService().getTower()).thenReturn(TowerType.WEAPON); - TiledMapTileLayer mockTileLayer = mock(TiledMapTileLayer.class); - when(mockLayers.get(0)).thenReturn(mockTileLayer); + ServiceLocator.registerEntityService(mock(EntityService.class)); + when(ServiceLocator.getEntityService().entitiesInTile(2,4)).thenReturn(Boolean.FALSE); - TiledMapTileLayer.Cell mockCell = mock(TiledMapTileLayer.Cell.class); - when(mockTileLayer.getCell(2, 4)).thenReturn(mockCell); + when(ServiceLocator.getCurrencyService().getScrap()).thenReturn(mock(Scrap.class)); + when(ServiceLocator.getCurrencyService().getScrap().canBuy(Integer.parseInt(ServiceLocator.getCurrencyService().getTower().getPrice()))).thenReturn(Boolean.TRUE); + // The tile should turn green since it meets the requirement + when(ServiceLocator.getResourceService().getAsset("images/green_tile.png", Texture.class)) + .thenReturn(mockTexture); - TiledMapTile mockTile = mock(TiledMapTile.class); - when(mockCell.getTile()).thenReturn(mockTile); + component.hoverHighlight(); + // Verify that the tile's texture region was changed + verify(mockTile).setTextureRegion(any(TextureRegion.class)); + } + @Test + void shouldHighlightTileRedOnHover() { Texture mockTexture = mock(Texture.class); ServiceLocator.registerResourceService(mock(ResourceService.class)); ServiceLocator.registerCurrencyService(mock(CurrencyService.class)); - when(ServiceLocator.getCurrencyService().getTower()).thenReturn(TowerType.WEAPON); + when(ServiceLocator.getCurrencyService().getTower()).thenReturn(TowerType.TNT); ServiceLocator.registerEntityService(mock(EntityService.class)); when(ServiceLocator.getEntityService().entitiesInTile(2,4)).thenReturn(Boolean.FALSE); when(ServiceLocator.getCurrencyService().getScrap()).thenReturn(mock(Scrap.class)); - when(ServiceLocator.getCurrencyService().getScrap().canBuy(Integer.parseInt(ServiceLocator.getCurrencyService().getTower().getPrice()))).thenReturn(Boolean.TRUE); - // The tile should turn green since it meets the requirement - when(ServiceLocator.getResourceService().getAsset("images/green_tile.png", Texture.class)) + when(ServiceLocator.getCurrencyService().getScrap().canBuy(Integer.parseInt(ServiceLocator.getCurrencyService().getTower().getPrice()))).thenReturn(Boolean.FALSE); + // The tile should turn red since we can't afford the tower + when(ServiceLocator.getResourceService().getAsset("images/red_tile.png", Texture.class)) .thenReturn(mockTexture); component.hoverHighlight(); diff --git a/source/core/src/test/com/csse3200/game/rendering/CameraShakerTest.java b/source/core/src/test/com/csse3200/game/rendering/CameraShakerTest.java new file mode 100644 index 000000000..303f36277 --- /dev/null +++ b/source/core/src/test/com/csse3200/game/rendering/CameraShakerTest.java @@ -0,0 +1,42 @@ +package com.csse3200.game.rendering; + +import com.badlogic.gdx.graphics.OrthographicCamera; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +public class CameraShakerTest { + + private CameraShaker cameraShaker; + private OrthographicCamera camera; + + @BeforeEach + public void setUp() { + camera = new OrthographicCamera(); + cameraShaker = new CameraShaker(camera); + } + + @Test + public void testStartShaking() { + assertFalse(cameraShaker.isCameraShaking()); + cameraShaker.startShaking(); + assertTrue(cameraShaker.isCameraShaking()); + } + + @Test + public void testReset() { + cameraShaker.startShaking(); + cameraShaker.reset(); + assertFalse(cameraShaker.isCameraShaking()); + assertEquals(cameraShaker.origPosition, camera.position); + } + + @Test + public void testDefaultConstructorValues() { + assertEquals(0.05f, cameraShaker.getShakeRadius(), 0.001f); + assertEquals(0.001f, cameraShaker.getMinimumRadius(), 0.001f); + assertEquals(0.8f, cameraShaker.getFallOffFactor(), 0.001f); + } + +}