From 05ec6f63fb8dcb6fe9f7333f47f74807b8a65bd0 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Wed, 16 Oct 2024 09:50:05 +1000 Subject: [PATCH 01/29] change meter position --- .../csse3200/game/components/upgrades/DancePartyUpgrade.java | 2 +- .../com/csse3200/game/components/upgrades/ExtortionUpgrade.java | 2 +- .../csse3200/game/components/upgrades/SpeedBootsUpgrade.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index e37cbee8e..3b8f92425 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -107,7 +107,7 @@ private void setupMeter() { meter = new ProgressBar(0f, 1f, 0.01f, false, style); meter.setValue(1f); - meter.setPosition(8, 500); + meter.setPosition(30, 250); text = new Label("Upgrade", skin); text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java index d751243b5..486b2e41c 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java @@ -90,7 +90,7 @@ private void setupMeter() { if (isActive) { meter = new ProgressBar(0f, 1f, 0.01f, false, style); meter.setValue(1f); // Initially, the meter is full - meter.setPosition(8, 500); + meter.setPosition(30, 2500); // Set up text text = new Label("Upgrade", skin); diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/SpeedBootsUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/SpeedBootsUpgrade.java index ba6bc6fed..74c023f7e 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/SpeedBootsUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/SpeedBootsUpgrade.java @@ -167,7 +167,7 @@ private void setupSpeedMeter() { if (isActivate) { speedMeter = new ProgressBar(0f, 1f, 0.01f, false, style); speedMeter.setValue(1f); // Initially, the meter is full - speedMeter.setPosition(8, 500); + speedMeter.setPosition(30, 250); // Set up text text = new Label("Upgrade", skin); From ad56760a7806c20df49d5e0ce653c0dae3bc544d Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 10:14:50 +1000 Subject: [PATCH 02/29] Added dependency injection for docket service event Handler. Tested dance party activation --- .../upgrades/DancePartyUpgrade.java | 12 +++++++++ .../csse3200/game/services/DocketService.java | 6 ++++- .../upgrades/DancePartyUpgradeTest.java | 27 ++++++++++++++++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index e37cbee8e..ae24ddc3d 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -195,4 +195,16 @@ protected void draw(SpriteBatch batch) { public void setStage(Stage mock) { this.stage = mock; } + + public boolean isActive() { + return isActive; + } + + public float getActiveTimeRemaining() { + return activeTimeRemaining; + } + + public long getUpgradeDuration() { + return UPGRADE_DURATION; + } } diff --git a/source/core/src/main/com/csse3200/game/services/DocketService.java b/source/core/src/main/com/csse3200/game/services/DocketService.java index 3f2d854f7..cd7fdf682 100644 --- a/source/core/src/main/com/csse3200/game/services/DocketService.java +++ b/source/core/src/main/com/csse3200/game/services/DocketService.java @@ -14,7 +14,11 @@ public class DocketService { * Initialises the EventHandler that will manage all docket-related events. */ public DocketService() { - docketEventHandler = new EventHandler(); + this(new EventHandler()); + } + + public DocketService(EventHandler docketEventHandler) { + this.docketEventHandler = docketEventHandler; } diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index e9be3c956..3531babb0 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -40,21 +40,26 @@ public class DancePartyUpgradeTest { @Mock Label mockText; @Mock CombatStatsComponent combatStatsComponent; @Mock KeyboardPlayerInputComponent keyboardPlayerInputComponent; - private EventHandler eventHandler; + private EventHandler randomComboEventHandler; + private EventHandler docketEventHandler; RandomComboService randomComboService; + DocketService docketService; private DancePartyUpgrade dancePartyUpgrade; @BeforeEach void setUp() { ServiceLocator.clear(); - eventHandler = new EventHandler(); - randomComboService = new RandomComboService(eventHandler); + randomComboEventHandler = new EventHandler(); + docketEventHandler = new EventHandler(); + randomComboService = new RandomComboService(randomComboEventHandler); + docketService = new DocketService(randomComboEventHandler); ServiceLocator.registerRandomComboService(randomComboService); ServiceLocator.registerRenderService(renderService); ServiceLocator.registerResourceService(resourceService); ServiceLocator.registerTimeSource(gameTime); + ServiceLocator.registerDocketService(docketService); lenient().when(resourceService.getAsset(anyString(), eq(Texture.class))).thenReturn(textureMock); lenient().when(renderService.getStage()).thenReturn(stage); @@ -70,8 +75,22 @@ void setUp() { } @Test - void testNotNull() { + void testDancePartyActivates() { assertNotNull(dancePartyUpgrade); + when(combatStatsComponent.getGold()).thenReturn(100); + dancePartyUpgrade.activate(); + + AtomicBoolean isActive = new AtomicBoolean(false); + docketEventHandler.addListener("Dancing", () -> { + isActive.set(true); + }); + docketEventHandler.trigger("Dancing"); + + assertTrue(isActive.get()); + assertTrue(dancePartyUpgrade.isActive()); + assertTrue(dancePartyUpgrade.layout.isVisible()); + assertEquals(dancePartyUpgrade.getActiveTimeRemaining(), dancePartyUpgrade.getUpgradeDuration()); + verify(combatStatsComponent).addGold(-20); } @AfterEach From 25d829fe39193a8d8994ac4cc8ad941aa800a082 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Wed, 16 Oct 2024 10:16:07 +1000 Subject: [PATCH 03/29] meter is able to display when extortion upgrade is activate --- .../components/upgrades/ExtortionUpgrade.java | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java index 486b2e41c..a59bb39a6 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java @@ -61,6 +61,7 @@ public void create() { layout = new Table(); layout.setFillParent(true); layout.setVisible(isVisible); + setupMeter(); } /** @@ -68,37 +69,31 @@ public void create() { * Also initializes the accompanying label. */ private void setupMeter() { - Texture whiteBgTexture = ServiceLocator - .getResourceService().getAsset("images/white_background.png", Texture.class); - Texture fillTexture = ServiceLocator - .getResourceService().getAsset("images/green_fill.png", Texture.class); + if (meter == null) { + Texture whiteBgTexture = ServiceLocator.getResourceService().getAsset("images/white_background.png", Texture.class); + Texture fillTexture = ServiceLocator.getResourceService().getAsset("images/green_fill.png", Texture.class); - ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(); + ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(); + style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); + style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); - // Setting white background - style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); - style.background.setMinHeight(15); - style.background.setMinWidth(10); + style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); + style.background.setMinHeight(15); + style.background.setMinWidth(10); - // Setting green fill color - style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); - style.knobBefore.setMinHeight(15); - style.background.setMinWidth(10); + // Setting green fill color + style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); + style.knobBefore.setMinHeight(15); + style.background.setMinWidth(10); - - // Only show the speed meter if it is activated - if (isActive) { meter = new ProgressBar(0f, 1f, 0.01f, false, style); - meter.setValue(1f); // Initially, the meter is full - meter.setPosition(30, 2500); + meter.setValue(1f); + meter.setPosition(30, 250); - // Set up text text = new Label("Upgrade", skin); - text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); // Placed above meter - } - else { - meter = null; - text = null; + text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); + layout.add(text).row(); + layout.add(meter); } } @@ -116,7 +111,6 @@ public void activate() { activateTimeRemaining = upgradeDuration; isVisible = true; layout.setVisible(true); - setupMeter(); } else { ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney"); @@ -134,11 +128,9 @@ public void deactivate() { layout.setVisible(false); ServiceLocator.getRandomComboService().getEvents().trigger("extortion unactive"); - // Ensure the text and meter are removed from the stage after time finish - if (meter != null && meter.hasParent()) { - meter.remove(); - text.remove(); - } + + meter.remove(); + text.remove(); } public boolean isActive() { From a8f3558ab1f8067d32d80880ba38da9268283225 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Wed, 16 Oct 2024 10:30:13 +1000 Subject: [PATCH 04/29] reset the screen for entity when restart button is pressed --- .../com/csse3200/game/components/maingame/PauseMenuDisplay.java | 1 + 1 file changed, 1 insertion(+) diff --git a/source/core/src/main/com/csse3200/game/components/maingame/PauseMenuDisplay.java b/source/core/src/main/com/csse3200/game/components/maingame/PauseMenuDisplay.java index d924d41cd..bb0deead4 100644 --- a/source/core/src/main/com/csse3200/game/components/maingame/PauseMenuDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/maingame/PauseMenuDisplay.java @@ -148,6 +148,7 @@ public void clicked(InputEvent event, float x, float y) { @Override public void changed(ChangeEvent changeEvent, Actor actor) { logger.debug("Restart button clicked"); + game.resetScreen(); entity.getEvents().trigger("restart"); } }); From d249def75daaf603d41a029d80c631a0b78e561e Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 10:34:46 +1000 Subject: [PATCH 05/29] Added test for dancy party deactivation --- .../upgrades/DancePartyUpgradeTest.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index 3531babb0..b7e6d004d 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -53,7 +53,7 @@ void setUp() { randomComboEventHandler = new EventHandler(); docketEventHandler = new EventHandler(); randomComboService = new RandomComboService(randomComboEventHandler); - docketService = new DocketService(randomComboEventHandler); + docketService = spy(new DocketService(randomComboEventHandler)); ServiceLocator.registerRandomComboService(randomComboService); ServiceLocator.registerRenderService(renderService); @@ -93,6 +93,27 @@ void testDancePartyActivates() { verify(combatStatsComponent).addGold(-20); } + @Test + void testDancePartyDeactivates() { + dancePartyUpgrade.activate(); + lenient().when(meter.hasParent()).thenReturn(true); + dancePartyUpgrade.deactivate(); + + AtomicBoolean isActive = new AtomicBoolean(false); + docketEventHandler.addListener("UnDancing", () -> { + isActive.set(true); + }); + docketEventHandler.trigger("UnDancing"); + + assertTrue(isActive.get()); + verify(dancePartyUpgrade.meter).remove(); + verify(dancePartyUpgrade.text).remove(); + + assertFalse(dancePartyUpgrade.isActive()); + assertFalse(dancePartyUpgrade.layout.isVisible()); + assertEquals(0f, dancePartyUpgrade.meter.getValue()); + } + @AfterEach void tearDown() { ServiceLocator.clear(); From 4a54977f36acd9a0e6fab33f913e68e603e792c4 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 10:38:36 +1000 Subject: [PATCH 06/29] Added test for resource disposal, dance party upgrade --- .../game/components/upgrades/DancePartyUpgradeTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index b7e6d004d..ee87fde6e 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -114,6 +114,13 @@ void testDancePartyDeactivates() { assertEquals(0f, dancePartyUpgrade.meter.getValue()); } + @Test + void testDispose() { + dancePartyUpgrade.dispose(); + verify(resourceService).unloadAssets(SpeedBootsUpgrade.whiteBgTexture); + verify(resourceService).unloadAssets(SpeedBootsUpgrade.greenTexture); + } + @AfterEach void tearDown() { ServiceLocator.clear(); From 997f1b44214bbd9157f77c1720dc2da2ca6d0ece Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 11:07:29 +1000 Subject: [PATCH 07/29] Tested gold behavior for dancy party upgrade --- .../upgrades/DancePartyUpgrade.java | 3 ++ .../upgrades/DancePartyUpgradeTest.java | 45 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index 846e84c48..a46faeef9 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -130,6 +130,9 @@ public void activate() { ServiceLocator.getDocketService().getEvents().trigger("Dancing"); } + else{ + ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney"); + } } /** diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index ee87fde6e..9f378714e 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -90,7 +90,6 @@ void testDancePartyActivates() { assertTrue(dancePartyUpgrade.isActive()); assertTrue(dancePartyUpgrade.layout.isVisible()); assertEquals(dancePartyUpgrade.getActiveTimeRemaining(), dancePartyUpgrade.getUpgradeDuration()); - verify(combatStatsComponent).addGold(-20); } @Test @@ -114,6 +113,50 @@ void testDancePartyDeactivates() { assertEquals(0f, dancePartyUpgrade.meter.getValue()); } + @Test + void testLoseGoldOnPurchase() { + when(combatStatsComponent.getGold()).thenReturn(100); + dancePartyUpgrade.activate(); + verify(combatStatsComponent).addGold(-20); + } + + @Test + void testInsufficientGold() { + when(combatStatsComponent.getGold()).thenReturn(10); + AtomicBoolean notEnoughMoney = new AtomicBoolean(false); + randomComboEventHandler.addListener("notenoughmoney", () -> { + notEnoughMoney.set(true); + }); + + dancePartyUpgrade.activate(); + + assertTrue(notEnoughMoney.get()); + assertFalse(dancePartyUpgrade.isActive()); + assertFalse(dancePartyUpgrade.layout.isVisible()); + } + +/* @Test + void testSpeedBootsFor30Seconds() { + DancePartyUpgrade spyDancePartyUpgrade = spy(dancePartyUpgrade); + when(combatStatsComponent.getGold()).thenReturn(100); + spyDancePartyUpgrade.activate(); + + when(gameTime.getDeltaTime()).thenReturn(1f); + for (int i = 0; i < 15; i++) { + spyDancePartyUpgrade.update(); + } + +// assertEquals(spyDancePartyUpgrade.getActiveTimeRemaining() / +// (float) spyDancePartyUpgrade.getBoostDuration(), spyDancePartyUpgrade.speedMeter.getValue()); + + for (int i = 0; i < 15; i++) { + spyDancePartyUpgrade.update(); + } + + verify(spyDancePartyUpgrade).deactivate(); +// assertFalse(spyDancePartyUpgrade.getPlaySound()); + }*/ + @Test void testDispose() { dancePartyUpgrade.dispose(); From b480050c5db80796b88c56a0a4412df65f2479b3 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 12:24:10 +1000 Subject: [PATCH 08/29] Tried to test meter behaviour for Dance party upgrade. Found Issues. --- .../components/upgrades/DancePartyUpgrade.java | 18 +++++++++++------- .../upgrades/DancePartyUpgradeTest.java | 17 +++++++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index a46faeef9..a8e7820bd 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -175,13 +175,13 @@ public void update() { } } - if (Gdx.input.isKeyJustPressed(Input.Keys.V)) { - if (isActive) { - deactivate(); - } else { - activate(); - } - } +// if (Gdx.input.isKeyJustPressed(Input.Keys.V)) { +// if (isActive) { +// deactivate(); +// } else { +// activate(); +// } +// } } @Override @@ -210,4 +210,8 @@ public float getActiveTimeRemaining() { public long getUpgradeDuration() { return UPGRADE_DURATION; } + + public boolean getPlaySound() { + return playSound; + } } diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index 9f378714e..242b47d1e 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -86,6 +86,8 @@ void testDancePartyActivates() { }); docketEventHandler.trigger("Dancing"); + // Dance Party Issue: Can't verify meter value is 1f upon activation/setup. Needs to be setup properly. +// assertEquals(1f, dancePartyUpgrade.meter.getValue()); assertTrue(isActive.get()); assertTrue(dancePartyUpgrade.isActive()); assertTrue(dancePartyUpgrade.layout.isVisible()); @@ -135,11 +137,10 @@ void testInsufficientGold() { assertFalse(dancePartyUpgrade.layout.isVisible()); } -/* @Test - void testSpeedBootsFor30Seconds() { + @Test + void testDancePartyFor30Seconds() { DancePartyUpgrade spyDancePartyUpgrade = spy(dancePartyUpgrade); when(combatStatsComponent.getGold()).thenReturn(100); - spyDancePartyUpgrade.activate(); when(gameTime.getDeltaTime()).thenReturn(1f); for (int i = 0; i < 15; i++) { @@ -147,15 +148,19 @@ void testSpeedBootsFor30Seconds() { } // assertEquals(spyDancePartyUpgrade.getActiveTimeRemaining() / -// (float) spyDancePartyUpgrade.getBoostDuration(), spyDancePartyUpgrade.speedMeter.getValue()); +// (float) spyDancePartyUpgrade.getUpgradeDuration(), spyDancePartyUpgrade.meter.getValue()); for (int i = 0; i < 15; i++) { spyDancePartyUpgrade.update(); } + assertEquals(0, spyDancePartyUpgrade.getActiveTimeRemaining()); + + // can't verify deactivation after 30 seconds pass. Needs to be setup properly. +// verify(spyDancePartyUpgrade).deactivate(); - verify(spyDancePartyUpgrade).deactivate(); + // can't verify sound is played upon deactivation, if that even happens. // assertFalse(spyDancePartyUpgrade.getPlaySound()); - }*/ + } @Test void testDispose() { From d53609efd7f40bdd40e9e95a3aa86c1bbdf6c175 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 12:31:31 +1000 Subject: [PATCH 09/29] Accidentally deleted a line in test which caused build to fail. Fixed it up. --- .../csse3200/game/components/upgrades/DancePartyUpgradeTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index 242b47d1e..ee677db7f 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -141,6 +141,7 @@ void testInsufficientGold() { void testDancePartyFor30Seconds() { DancePartyUpgrade spyDancePartyUpgrade = spy(dancePartyUpgrade); when(combatStatsComponent.getGold()).thenReturn(100); + spyDancePartyUpgrade.activate(); when(gameTime.getDeltaTime()).thenReturn(1f); for (int i = 0; i < 15; i++) { From 9a1bd20da6fafacea246d5ed21e97d7b2a3f5542 Mon Sep 17 00:00:00 2001 From: Ashwin Harikrishna Date: Wed, 16 Oct 2024 13:13:07 +1000 Subject: [PATCH 10/29] dance party fix --- .../MainGameOrderTicketDisplay.java | 63 ++++++++++++++----- .../game/services/RandomComboService.java | 2 +- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java index fdb61c3a4..fa4c28f5c 100644 --- a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java @@ -64,6 +64,8 @@ public class MainGameOrderTicketDisplay extends UIComponent { private boolean isPaused = false; private long pauseStartTime = 0; private long totalPausedDuration = 0; + private boolean isDancing = false; + // private static ArrayList textureArrayList; private static ArrayList imageArrayList; @@ -155,8 +157,15 @@ public void create() { ServiceLocator.getDocketService().getEvents().addListener("removeBigTicket", this::removeBigTicket); //From Team 2, these listeners are for our dance party upgrade to pause and unpause docket times - ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->{setPaused(true);}); - ServiceLocator.getDocketService().getEvents().addListener("UnDancing", ()->{setPaused(false);}); + ServiceLocator.getDocketService().getEvents().addListener("Dancing", () -> { + isDancing = true; + addTimeToDockets(300000); // 30 seconds in milliseconds + }); + ServiceLocator.getDocketService().getEvents().addListener("UnDancing", () -> { + isDancing = false; + }); + + //From team 2, I used your dispose method here when listening for a new day, so current dockets get removed //when the end of day occurs @@ -188,44 +197,56 @@ public void addActors() { logger.info("Adding actors"); Table table = new Table(); long startTime = TimeUtils.millis(); - + startTimeArrayList.add(startTime); tableArrayList.add(table); - + table.setFillParent(false); table.setSize(viewportWidth * 3f / 32f, 5f / 27f * viewportHeight); // DEFAULT_HEIGHT float xVal = cntXval(250f, tableArrayList.size()); float yVal = viewportHeight * viewPortHeightMultiplier; table.setPosition(xVal, yVal); table.padTop(25f); + + // Create a new docket for the background Docket background = new Docket(getTimer()); + + // Add 30 seconds to the timer if `isDancing` is true + long ticketTime = getTimer(); + if (isDancing) { + ticketTime += 300000; // Add 30 seconds in milliseconds + } + backgroundArrayList.add(background); table.setBackground(background.getImage().getDrawable()); - + String orderNumStr = "Order" + " " + ++orderNumb; Label orderNumbLabel = new Label(orderNumStr, skin); table.add(orderNumbLabel).padLeft(10f).row(); - + Label recipeNameLabel = new Label(getRecipe().getName(), skin); table.add(recipeNameLabel).padLeft(10f).row(); - - String s=getRecipe().getName(); + + String s = getRecipe().getName(); stringArrayList.add(s); - Texture texture=texture_map.get(mealDisplay.getMealImage(s,"vertical")); - mealImage=new Image(new TextureRegionDrawable(texture)); + Texture texture = texture_map.get(mealDisplay.getMealImage(s, "vertical")); + mealImage = new Image(new TextureRegionDrawable(texture)); imageArrayList.add(mealImage); table.add(mealImage).row(); - - recipeTimeArrayList.add(getTimer()); - Label countdownLabel = new Label("Timer: " + getTimer(), skin); + + // Store the calculated ticket time (either the original or extended time) + recipeTimeArrayList.add(ticketTime); + + Label countdownLabel = new Label("Timer: " + (ticketTime / 1000), skin); countdownLabelArrayList.add(countdownLabel); table.add(countdownLabel).padLeft(10f).row(); - + stage.addActor(table); updateDocketSizes(); - - table.setZIndex((int)getZIndex()); + + table.setZIndex((int) getZIndex()); } + /** * Calculates the x-position for an order ticket based on its index. @@ -490,6 +511,9 @@ public void update() { } // No additional update logic needed here, shifting is handled by the OrderActions class + // if(isDancing){ + // addTimeToDockets(50); + // } for (int i = 0; i < tableArrayList.size(); i++) { Docket currBackground = backgroundArrayList.get(i); Table currTable = tableArrayList.get(i); @@ -697,4 +721,11 @@ public static ArrayList getRecipeTimeArrayList() { return recipeTimeArrayList; } + private void addTimeToDockets(long additionalTime) { + for (int i = 0; i < recipeTimeArrayList.size(); i++) { + recipeTimeArrayList.set(i, recipeTimeArrayList.get(i) + additionalTime); + } + } + + } diff --git a/source/core/src/main/com/csse3200/game/services/RandomComboService.java b/source/core/src/main/com/csse3200/game/services/RandomComboService.java index bd6c63310..cb6356558 100644 --- a/source/core/src/main/com/csse3200/game/services/RandomComboService.java +++ b/source/core/src/main/com/csse3200/game/services/RandomComboService.java @@ -26,7 +26,7 @@ public class RandomComboService extends Component { private Random random; int randomChoice; private EventHandler eventHandler; - private int total_upgrades = 4; + private int total_upgrades = 1; public RandomComboService() { this(new EventHandler()); From 79695f864d9370aabdaead27d154b21ebe7c4c58 Mon Sep 17 00:00:00 2001 From: Ashwin Harikrishna Date: Wed, 16 Oct 2024 13:52:47 +1000 Subject: [PATCH 11/29] danceparty --- .../game/services/RandomComboService.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/services/RandomComboService.java b/source/core/src/main/com/csse3200/game/services/RandomComboService.java index f70368e04..cb6356558 100644 --- a/source/core/src/main/com/csse3200/game/services/RandomComboService.java +++ b/source/core/src/main/com/csse3200/game/services/RandomComboService.java @@ -46,16 +46,16 @@ public String getSelectedUpgrade() { String upgrade; switch (randomChoice) { - // case 0: - // upgrade = "Extortion"; - // break; - // case 1: - // upgrade = "Loan"; - // break; - // case 2: - // upgrade = "Speed"; - // break; case 0: + upgrade = "Extortion"; + break; + case 1: + upgrade = "Loan"; + break; + case 2: + upgrade = "Speed"; + break; + case 3: upgrade = "Dance party"; break; default: From 802797e0233898bd6ad0fbd6fc9f5de9e5dd0bef Mon Sep 17 00:00:00 2001 From: Ashwin Harikrishna Date: Wed, 16 Oct 2024 14:11:44 +1000 Subject: [PATCH 12/29] bug choices --- .../src/main/com/csse3200/game/services/RandomComboService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/core/src/main/com/csse3200/game/services/RandomComboService.java b/source/core/src/main/com/csse3200/game/services/RandomComboService.java index cb6356558..bd6c63310 100644 --- a/source/core/src/main/com/csse3200/game/services/RandomComboService.java +++ b/source/core/src/main/com/csse3200/game/services/RandomComboService.java @@ -26,7 +26,7 @@ public class RandomComboService extends Component { private Random random; int randomChoice; private EventHandler eventHandler; - private int total_upgrades = 1; + private int total_upgrades = 4; public RandomComboService() { this(new EventHandler()); From 7f9a06957e0f4682d5ce79270516d76779eb6a60 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Wed, 16 Oct 2024 14:23:18 +1000 Subject: [PATCH 13/29] remove loan keybind and the staement check for gold --- .../game/components/upgrades/LoanUpgrade.java | 16 +++---- .../components/upgrades/LoanUpgradeTest.java | 44 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java index ad28ee390..0c52d8e4a 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java @@ -28,16 +28,16 @@ public LoanUpgrade(){ * at least 20 gold */ public void activate() { - if(combatStatsComponent.getGold() >= 20){ +// if(combatStatsComponent.getGold() >= 20){ // https://pixabay.com/sound-effects/cha-ching-7053/ Sound moneySound = Gdx.audio.newSound(Gdx.files.internal("sounds/loan.mp3")); long moneySoundId = moneySound.play(); moneySound.setVolume(moneySoundId, 0.2f); combatStatsComponent.addGold(100); - } - else{ - ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney"); - } +// } +// else{ +// ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney"); +// } } /** @@ -48,8 +48,8 @@ public void deactivate() {} @Override public void update() { // Check if the 'L' key is pressed in each frame - if (Gdx.input.isKeyJustPressed(Input.Keys.L)) { - activate(); // Add 100 gold when 'L' is pressed - } +// if (Gdx.input.isKeyJustPressed(Input.Keys.L)) { +// activate(); // Add 100 gold when 'L' is pressed +// } } } diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java index 908c464b2..da84320b1 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java @@ -57,32 +57,32 @@ public void tearDown() { @Test public void activate_shouldAddGold_WhenGoldIsSufficient() { - when(combatStatsComponent.getGold()).thenReturn(20); +// when(combatStatsComponent.getGold()).thenReturn(20); loanUpgrade.activate(); verify(combatStatsComponent).addGold(100); } - @Test - public void activate_shouldTriggerNotEnoughMoneyEvent_WhenGoldIsInsufficient() { - when(combatStatsComponent.getGold()).thenReturn(10); - loanUpgrade.activate(); - verify(randomComboServiceEvents).trigger("notenoughmoney"); - } +// @Test +// public void activate_shouldTriggerNotEnoughMoneyEvent_WhenGoldIsInsufficient() { +// when(combatStatsComponent.getGold()).thenReturn(10); +// loanUpgrade.activate(); +// verify(randomComboServiceEvents).trigger("notenoughmoney"); +// } - @Test - public void update_shouldCallActivate_WhenLKeyIsPressed() throws Exception { - MockedStatic gdxMock = mockStatic(Gdx.class); - Input mockInput = mock(Input.class); - - Field inputField = Gdx.class.getDeclaredField("input"); - inputField.setAccessible(true); - inputField.set(null, mockInput); - - when(mockInput.isKeyJustPressed(Input.Keys.L)).thenReturn(true); - LoanUpgrade loanUpgradeSpy = spy(loanUpgrade); - loanUpgradeSpy.update(); - verify(loanUpgradeSpy).activate(); - gdxMock.close(); - } +// @Test +// public void update_shouldCallActivate_WhenLKeyIsPressed() throws Exception { +// MockedStatic gdxMock = mockStatic(Gdx.class); +// Input mockInput = mock(Input.class); +// +// Field inputField = Gdx.class.getDeclaredField("input"); +// inputField.setAccessible(true); +// inputField.set(null, mockInput); +// +// when(mockInput.isKeyJustPressed(Input.Keys.L)).thenReturn(true); +// LoanUpgrade loanUpgradeSpy = spy(loanUpgrade); +// loanUpgradeSpy.update(); +// verify(loanUpgradeSpy).activate(); +// gdxMock.close(); +// } } From 2987c352b927a8c5389b24c1ac4d802ee5cbbff6 Mon Sep 17 00:00:00 2001 From: Joanna Wang Date: Wed, 16 Oct 2024 14:32:34 +1000 Subject: [PATCH 14/29] remove unnecessary/unused code in loan upgrade --- .../game/components/upgrades/LoanUpgrade.java | 20 +++++----------- .../components/upgrades/LoanUpgradeTest.java | 24 ------------------- 2 files changed, 6 insertions(+), 38 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java index 0c52d8e4a..db08577ca 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/LoanUpgrade.java @@ -28,16 +28,11 @@ public LoanUpgrade(){ * at least 20 gold */ public void activate() { -// if(combatStatsComponent.getGold() >= 20){ - // https://pixabay.com/sound-effects/cha-ching-7053/ - Sound moneySound = Gdx.audio.newSound(Gdx.files.internal("sounds/loan.mp3")); - long moneySoundId = moneySound.play(); - moneySound.setVolume(moneySoundId, 0.2f); - combatStatsComponent.addGold(100); -// } -// else{ -// ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney"); -// } + // https://pixabay.com/sound-effects/cha-ching-7053/ + Sound moneySound = Gdx.audio.newSound(Gdx.files.internal("sounds/loan.mp3")); + long moneySoundId = moneySound.play(); + moneySound.setVolume(moneySoundId, 0.2f); + combatStatsComponent.addGold(100); } /** @@ -47,9 +42,6 @@ public void deactivate() {} @Override public void update() { - // Check if the 'L' key is pressed in each frame -// if (Gdx.input.isKeyJustPressed(Input.Keys.L)) { -// activate(); // Add 100 gold when 'L' is pressed -// } + } } diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java index da84320b1..7ce4e29f7 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/LoanUpgradeTest.java @@ -57,32 +57,8 @@ public void tearDown() { @Test public void activate_shouldAddGold_WhenGoldIsSufficient() { -// when(combatStatsComponent.getGold()).thenReturn(20); loanUpgrade.activate(); verify(combatStatsComponent).addGold(100); } -// @Test -// public void activate_shouldTriggerNotEnoughMoneyEvent_WhenGoldIsInsufficient() { -// when(combatStatsComponent.getGold()).thenReturn(10); -// loanUpgrade.activate(); -// verify(randomComboServiceEvents).trigger("notenoughmoney"); -// } - -// @Test -// public void update_shouldCallActivate_WhenLKeyIsPressed() throws Exception { -// MockedStatic gdxMock = mockStatic(Gdx.class); -// Input mockInput = mock(Input.class); -// -// Field inputField = Gdx.class.getDeclaredField("input"); -// inputField.setAccessible(true); -// inputField.set(null, mockInput); -// -// when(mockInput.isKeyJustPressed(Input.Keys.L)).thenReturn(true); -// LoanUpgrade loanUpgradeSpy = spy(loanUpgrade); -// loanUpgradeSpy.update(); -// verify(loanUpgradeSpy).activate(); -// gdxMock.close(); -// } - } From 63e4a384a361a546c7668cdad8e4b4b6fbb317ba Mon Sep 17 00:00:00 2001 From: willembor Date: Wed, 16 Oct 2024 14:43:47 +1000 Subject: [PATCH 15/29] added doc strings to all the functions in DancePartyUpgrade --- .../upgrades/DancePartyUpgrade.java | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index a8e7820bd..1894cb92f 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -44,6 +44,10 @@ public class DancePartyUpgrade extends UIComponent implements Upgrade { private boolean playSound = false; + /** + * Constructor for DancePartyUpgrade that initializes the upgrade and sets up event listeners. + * It listens for "playerCreated" and "Dance party" events. + */ public DancePartyUpgrade() { ServiceLocator.getPlayerService().getEvents().addListener("playerCreated", (Entity player) -> { this.combatStatsComponent = player.getComponent(CombatStatsComponent.class); @@ -56,6 +60,12 @@ public DancePartyUpgrade() { ServiceLocator.getRandomComboService().getEvents().addListener("Dance partyoff", this::deactivate); } + /** + * Constructor for DancePartyUpgrade with an explicit CombatStatsComponent. + * This initializes the upgrade and registers the same event listeners as the default constructor. + * + * @param combatStatsComponent the CombatStatsComponent for the player + */ public DancePartyUpgrade(CombatStatsComponent combatStatsComponent) { this.combatStatsComponent = combatStatsComponent; this.orderManager = orderManager; @@ -66,6 +76,11 @@ public DancePartyUpgrade(CombatStatsComponent combatStatsComponent) { ServiceLocator.getRandomComboService().getEvents().addListener("Dance partyoff", this::deactivate); } + /** + * Initializes the Dance Party upgrade by loading necessary assets, + * such as textures and sound effects, and setting up the UI components + * (progress meter and label). This method is called when the component is created. + */ @Override public void create() { super.create(); @@ -149,11 +164,17 @@ public void deactivate() { ServiceLocator.getDocketService().getEvents().trigger("UnDancing"); } - + /** + * Handles the cost of the Dance Party upgrade, deducting gold from the player's CombatStatsComponent. + */ public void dancePartyCost() { combatStatsComponent.addGold(-20); } + /** + * Checks and updates the remaining time for the Dance Party upgrade, updating the progress bar meter. + * It also checks if the upgrade's time has run out and deactivates it accordingly. + */ @Override public void update() { if (isActive) { @@ -184,33 +205,69 @@ public void update() { // } } + /** + * Disposes of assets and cleans up when the upgrade is no longer needed. + * Unloads the textures used by the upgrade. + */ @Override public void dispose() { super.dispose(); ServiceLocator.getResourceService().unloadAssets(whiteBgTexture); ServiceLocator.getResourceService().unloadAssets(greenTexture); } + + /** + * Draw method required by the UIComponent class, but not used in this upgrade. + * + * @param batch the SpriteBatch used to draw + */ @Override protected void draw(SpriteBatch batch) { } + + /** + * Sets the stage for the UI components, such as the layout, meter, and text. + * + * @param mock the Stage to which the UI components belong + */ @Override public void setStage(Stage mock) { this.stage = mock; } + /** + * Gets the current active state of the Dance Party upgrade. + * + * @return true if the upgrade is currently active, false otherwise + */ public boolean isActive() { return isActive; } + /** + * Retrieves the remaining time for which the upgrade will stay active. + * + * @return the remaining active time in milliseconds + */ public float getActiveTimeRemaining() { return activeTimeRemaining; } + /** + * Retrieves the total upgrade duration. + * + * @return the total duration of the upgrade in milliseconds + */ public long getUpgradeDuration() { return UPGRADE_DURATION; } + /** + * Retrieves the current state of the playSound flag, which indicates whether the upgrade's sound has been played. + * + * @return true if the sound has been played, false otherwise + */ public boolean getPlaySound() { return playSound; } From 9203fcdac982c5179acdceeed519480f653ada4c Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 15:37:36 +1000 Subject: [PATCH 16/29] Fixed bug for Dance party not increasing the order docket timer --- .../components/ordersystem/MainGameOrderTicketDisplay.java | 2 +- .../src/main/com/csse3200/game/screens/MainGameScreen.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java index d4c670f20..ce6451ccd 100644 --- a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java @@ -58,7 +58,7 @@ public class MainGameOrderTicketDisplay extends UIComponent { private boolean isPaused = false; private long pauseStartTime = 0; private long totalPausedDuration = 0; - private boolean isDancing = false; + private static boolean isDancing = false; private static final ArrayList imageArrayList = new ArrayList<>(); private static final ArrayList stringArrayList = new ArrayList<>(); diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index 3d82a243c..1be868928 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -335,7 +335,8 @@ private void createUI() { .addComponent(new PauseMenuActions(this.game)) .addComponent(new PauseMenuDisplay(this)) .addComponent(new UpgradesDisplay(this)) - .addComponent(new RecipeCardDisplay(this)); + .addComponent(new RecipeCardDisplay(this)) + .addComponent(new MainGameOrderTicketDisplay(ServiceLocator.getRenderService(), ServiceLocator.getPlayerService())); ServiceLocator.getEntityService().register(ui); } From 1c2b8c335995239e274a481cef24e3862825dbd4 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 16:23:31 +1000 Subject: [PATCH 17/29] Fixed setupMeter() so it sets up meter value 1f on activation. Corresponding tests have no issues now. --- .../upgrades/DancePartyUpgrade.java | 48 +++++++++++-------- .../upgrades/DancePartyUpgradeTest.java | 16 +++---- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index 1894cb92f..34966371c 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -37,7 +37,7 @@ public class DancePartyUpgrade extends UIComponent implements Upgrade { private static final String[] greenTexture = {"images/green_fill.png"}; private static final String[] whiteBgTexture = {"images/white_background.png"}; public Table layout; - public Label text; // the "Upgrade" text above the speedMeter + public Label text; // the "Upgrade" text above the meter public ProgressBar meter; // the meter that show the remaining time private boolean isVisible; private Sound bgEffect; @@ -93,7 +93,7 @@ public void create() { layout = new Table(); layout.setFillParent(true); layout.setVisible(false); - setupMeter(); +// setupMeter(); } @@ -103,31 +103,37 @@ public void create() { * Also initializes the accompanying label. */ private void setupMeter() { - if (meter == null) { - Texture whiteBgTexture = ServiceLocator.getResourceService().getAsset("images/white_background.png", Texture.class); - Texture fillTexture = ServiceLocator.getResourceService().getAsset("images/green_fill.png", Texture.class); + Texture whiteBgTexture = ServiceLocator + .getResourceService().getAsset("images/white_background.png", Texture.class); + Texture fillTexture = ServiceLocator + .getResourceService().getAsset("images/green_fill.png", Texture.class); - ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(); - style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); - style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); + ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(); - style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); - style.background.setMinHeight(15); - style.background.setMinWidth(10); + // Setting white background + style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); + style.background.setMinHeight(15); + style.background.setMinWidth(10); - // Setting green fill color - style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); - style.knobBefore.setMinHeight(15); - style.background.setMinWidth(10); + // Setting green fill color + style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); + style.knobBefore.setMinHeight(15); + style.background.setMinWidth(10); + + // Only show the speed meter if it is activated + if (isActive) { meter = new ProgressBar(0f, 1f, 0.01f, false, style); - meter.setValue(1f); + meter.setValue(1f); // Initially, the meter is full meter.setPosition(30, 250); - text = new Label("Upgrade", skin); - text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); - layout.add(text).row(); - layout.add(meter); + // Set up text + text = new Label("Upgrade", skin); + text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); // Placed above meter + } + else { + meter = null; + text = null; } } @@ -142,6 +148,8 @@ public void activate() { dancePartyCost(); isActive = true; layout.setVisible(true); + setupMeter(); + System.out.println("Dance party meter value on activate: " + meter.getValue()); ServiceLocator.getDocketService().getEvents().trigger("Dancing"); } diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index ee677db7f..5b0c47952 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -86,8 +86,7 @@ void testDancePartyActivates() { }); docketEventHandler.trigger("Dancing"); - // Dance Party Issue: Can't verify meter value is 1f upon activation/setup. Needs to be setup properly. -// assertEquals(1f, dancePartyUpgrade.meter.getValue()); + assertEquals(1f, dancePartyUpgrade.meter.getValue()); assertTrue(isActive.get()); assertTrue(dancePartyUpgrade.isActive()); assertTrue(dancePartyUpgrade.layout.isVisible()); @@ -148,19 +147,16 @@ void testDancePartyFor30Seconds() { spyDancePartyUpgrade.update(); } -// assertEquals(spyDancePartyUpgrade.getActiveTimeRemaining() / -// (float) spyDancePartyUpgrade.getUpgradeDuration(), spyDancePartyUpgrade.meter.getValue()); + assertEquals(spyDancePartyUpgrade.getActiveTimeRemaining() / + (float) spyDancePartyUpgrade.getUpgradeDuration(), spyDancePartyUpgrade.meter.getValue()); for (int i = 0; i < 15; i++) { spyDancePartyUpgrade.update(); } - assertEquals(0, spyDancePartyUpgrade.getActiveTimeRemaining()); - - // can't verify deactivation after 30 seconds pass. Needs to be setup properly. -// verify(spyDancePartyUpgrade).deactivate(); - // can't verify sound is played upon deactivation, if that even happens. -// assertFalse(spyDancePartyUpgrade.getPlaySound()); + assertEquals(0, spyDancePartyUpgrade.getActiveTimeRemaining()); + verify(spyDancePartyUpgrade).deactivate(); + assertFalse(spyDancePartyUpgrade.getPlaySound()); } @Test From b825ada5d9764ac279dbe4dbf9d80e01a3bbcc24 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Wed, 16 Oct 2024 16:40:14 +1000 Subject: [PATCH 18/29] Added parameterized tests for rage, speed, and dance party upgrades --- .../upgrades/DancePartyUpgradeTest.java | 18 ++++++++++++++++++ .../components/upgrades/RageUpgradeTest.java | 10 +++++++--- .../upgrades/SpeedBootsUpgradeTest.java | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index 5b0c47952..d461703b3 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -16,6 +16,8 @@ import com.csse3200.game.rendering.RenderService; import com.csse3200.game.services.*; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.*; import org.junit.jupiter.api.AfterEach; @@ -159,6 +161,22 @@ void testDancePartyFor30Seconds() { assertFalse(spyDancePartyUpgrade.getPlaySound()); } + @ParameterizedTest + @ValueSource(ints = {5, 10, 15, 20, 25, 30}) + void testMeterValueAtDifferentLevelsOfDepletion(int totalDepletedTime) { + DancePartyUpgrade spyDancePartyUpgrade = spy(dancePartyUpgrade); + when(combatStatsComponent.getGold()).thenReturn(100); + spyDancePartyUpgrade.activate(); + + when(gameTime.getDeltaTime()).thenReturn(1f); + for (int i = 0; i < totalDepletedTime; i++) { + spyDancePartyUpgrade.update(); + } + + assertEquals(spyDancePartyUpgrade.getActiveTimeRemaining() / + (float) spyDancePartyUpgrade.getUpgradeDuration(), spyDancePartyUpgrade.meter.getValue(), 0.01); + } + @Test void testDispose() { dancePartyUpgrade.dispose(); diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/RageUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/RageUpgradeTest.java index dbdd5d9da..f8fab9cec 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/RageUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/RageUpgradeTest.java @@ -22,6 +22,9 @@ import org.junit.jupiter.api.Test; import org.mockito.junit.jupiter.MockitoExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + @ExtendWith(GameExtension.class) @ExtendWith(MockitoExtension.class) public class RageUpgradeTest { @@ -115,11 +118,12 @@ void testRageMeterFillsIn90Seconds() { assertFalse(spyRageUpgrade.isRageFilling()); } - @Test - void testRageDeactivationBeforeDepletion() { + @ParameterizedTest + @ValueSource(floats = {0.25f, 0.5f, 0.75f}) + void testRageDeactivationBeforeDepletion(float rageMeterValue) { // Wanted to do parameterised testing here but need to ask about how to modify build.gradle for // @ParamterizedTest annotation - rageUpgrade.rageMeter.setValue(0.5f); + rageUpgrade.rageMeter.setValue(rageMeterValue); rageUpgrade.deactivateRageMode(); // 45 seconds diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/SpeedBootsUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/SpeedBootsUpgradeTest.java index 98d40595b..03c761fed 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/SpeedBootsUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/SpeedBootsUpgradeTest.java @@ -16,6 +16,8 @@ import com.csse3200.game.rendering.RenderService; import com.csse3200.game.services.*; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.*; import org.junit.jupiter.api.AfterEach; @@ -152,6 +154,22 @@ void testSpeedBootsFor30Seconds() { assertFalse(spySpeedBootsUpgrade.getPlaySound()); } + @ParameterizedTest + @ValueSource(ints = {5, 10, 15, 20, 25, 30}) + void testMeterValueAtDifferentLevelsOfDepletion(int totalDepletedTime) { + SpeedBootsUpgrade spySpeedBootsUpgrade = spy(speedBootsUpgrade); + when(combatStatsComponent.getGold()).thenReturn(100); + spySpeedBootsUpgrade.activate(); + + when(gameTime.getDeltaTime()).thenReturn(1f); + for (int i = 0; i < totalDepletedTime; i++) { + spySpeedBootsUpgrade.update(); + } + + assertEquals(spySpeedBootsUpgrade.getActiveTimeRemaining() / + (float) spySpeedBootsUpgrade.getBoostDuration(), spySpeedBootsUpgrade.speedMeter.getValue(), 0.01); + } + @Test void testDispose() { speedBootsUpgrade.dispose(); From 2966d1e8d60a04545964ba228b83ec9d960457f1 Mon Sep 17 00:00:00 2001 From: Ashwin Harikrishna Date: Wed, 16 Oct 2024 22:32:50 +1000 Subject: [PATCH 19/29] fixed dance party bug --- .../MainGameOrderTicketDisplay.java | 7 +---- .../upgrades/DancePartyUpgrade.java | 1 - .../game/entities/factories/NPCFactory.java | 26 +------------------ .../csse3200/game/screens/MainGameScreen.java | 3 +-- .../game/services/RandomComboService.java | 13 ++++++++++ 5 files changed, 16 insertions(+), 34 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java index ce6451ccd..83b9ee43d 100644 --- a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java @@ -58,7 +58,6 @@ public class MainGameOrderTicketDisplay extends UIComponent { private boolean isPaused = false; private long pauseStartTime = 0; private long totalPausedDuration = 0; - private static boolean isDancing = false; private static final ArrayList imageArrayList = new ArrayList<>(); private static final ArrayList stringArrayList = new ArrayList<>(); @@ -147,12 +146,8 @@ public void create() { //From Team 2, these listeners are for our dance party upgrade to pause and unpause docket times ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->{ - isDancing = true; addTimeToDockets(600000); }); - ServiceLocator.getDocketService().getEvents().addListener("UnDancing", ()->{ - isDancing = false; - }); //From team 2, I used your dispose method here when listening for a new day, so current dockets get removed //when the end of day occurs @@ -207,7 +202,7 @@ public void addActors() { // Check if Dancing is active, and add 60 seconds to the timer for new tickets long ticketTimer = getTimer(); - if (isDancing) { + if (ServiceLocator.getRandomComboService().dancing()) { ticketTimer += 600000; // Add 60 seconds } recipeTimeArrayList.add(ticketTimer); // Add adjusted time to the list diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index 1894cb92f..61599e982 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -142,7 +142,6 @@ public void activate() { dancePartyCost(); isActive = true; layout.setVisible(true); - ServiceLocator.getDocketService().getEvents().trigger("Dancing"); } else{ diff --git a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java index d3da0b5ca..e94e1db4a 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java @@ -102,7 +102,7 @@ public static Entity createUpgradeNPC(Vector2 firstPosition, UpgradesDisplay upg // Add a click event listener for the penguin penguin.getEvents().addListener("penguinactivated", ()->{ - if (!isClicked[0] && isHoverBox[0]) { + if (!isClicked[0] && isHoverBox[0] ) { hoverBox.setEnabled(false); logger.info("Penguin clicked!"); upgradesDisplay.create(); @@ -113,30 +113,6 @@ public static Entity createUpgradeNPC(Vector2 firstPosition, UpgradesDisplay upg } }); - // penguin.getEvents().addListener("clicked", (a, b) -> { - // if (a instanceof Float && b instanceof Float) { - // float x = ((Float) a); // cast a to float - // float y = ((Float) b); // cast b to float - - // // if ((penguin.getPosition().x - 0.3 <= x && x <= penguin.getPosition().x + 0.3) && - // // (penguin.getPosition().y - 0.5 <= y && y <= penguin.getPosition().y + 0.3)) { - // if ((penguin.getPosition().x - 1 <= x && x <= penguin.getPosition().x + 1) && - // (penguin.getPosition().y - 1 <= y && y <= penguin.getPosition().y + 1)) { - - // if (!isClicked[0] && isHoverBox[0]) { - // hoverBox.setEnabled(false); - // logger.info("Penguin clicked!"); - // upgradesDisplay.create(); - // upgradesDisplay.toggleVisibility(); - // isClicked[0] = true; - // } else { - // logger.info("Penguin has already been clicked, ignoring."); - // } - // } - // } - // }); - - // System.out.println("getting disposed of penguin"); ServiceLocator.getRandomComboService().getEvents().addListener("response", penguin::dispose); return penguin; } diff --git a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java index 1be868928..3d82a243c 100644 --- a/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java +++ b/source/core/src/main/com/csse3200/game/screens/MainGameScreen.java @@ -335,8 +335,7 @@ private void createUI() { .addComponent(new PauseMenuActions(this.game)) .addComponent(new PauseMenuDisplay(this)) .addComponent(new UpgradesDisplay(this)) - .addComponent(new RecipeCardDisplay(this)) - .addComponent(new MainGameOrderTicketDisplay(ServiceLocator.getRenderService(), ServiceLocator.getPlayerService())); + .addComponent(new RecipeCardDisplay(this)); ServiceLocator.getEntityService().register(ui); } diff --git a/source/core/src/main/com/csse3200/game/services/RandomComboService.java b/source/core/src/main/com/csse3200/game/services/RandomComboService.java index bd6c63310..3d3939582 100644 --- a/source/core/src/main/com/csse3200/game/services/RandomComboService.java +++ b/source/core/src/main/com/csse3200/game/services/RandomComboService.java @@ -27,6 +27,7 @@ public class RandomComboService extends Component { int randomChoice; private EventHandler eventHandler; private int total_upgrades = 4; + private boolean isDancing = false; public RandomComboService() { this(new EventHandler()); @@ -36,6 +37,13 @@ public RandomComboService(EventHandler eventHandler) { this.eventHandler = eventHandler; this.random = new Random(); randomChoice = random.nextInt(total_upgrades); + + ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->{ + isDancing = true; + }); + ServiceLocator.getDocketService().getEvents().addListener("UnDancing", ()->{ + isDancing = false; + }); } /** @@ -82,6 +90,11 @@ public void deactivateUpgrade() { public EventHandler getEvents() { return eventHandler; } + + public boolean dancing(){ + return isDancing; + + } } From 39bcfa0fde7d8767d3a31df275070fd5976a5fc5 Mon Sep 17 00:00:00 2001 From: Ashwin Harikrishna Date: Thu, 17 Oct 2024 01:43:51 +1000 Subject: [PATCH 20/29] fixed pause bug --- .../ordersystem/MainGameOrderTicketDisplay.java | 12 +++++++++++- .../game/components/upgrades/DancePartyUpgrade.java | 2 +- .../csse3200/game/entities/factories/NPCFactory.java | 5 ++++- .../csse3200/game/services/RandomComboService.java | 12 ++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java index 83b9ee43d..f2a06a621 100644 --- a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java @@ -145,10 +145,20 @@ public void create() { ServiceLocator.getDocketService().getEvents().addListener("removeBigTicket", this::removeBigTicket); //From Team 2, these listeners are for our dance party upgrade to pause and unpause docket times - ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->{ + // ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->{ + // addTimeToDockets(600000); + // }); + ServiceLocator.getRandomComboService().getEvents().addListener("Dancing", ()->{ addTimeToDockets(600000); }); + ServiceLocator.getDocketService().getEvents().addListener("paused", ()->{ + setPaused(true); + }); + ServiceLocator.getDocketService().getEvents().addListener("unpaused", ()->{ + setPaused(false); + }); + //From team 2, I used your dispose method here when listening for a new day, so current dockets get removed //when the end of day occurs ServiceLocator.getDocketService().getEvents().addListener("Dispose", this::dispose); diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java index 34966371c..59d4d1fe1 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/DancePartyUpgrade.java @@ -151,7 +151,7 @@ public void activate() { setupMeter(); System.out.println("Dance party meter value on activate: " + meter.getValue()); - ServiceLocator.getDocketService().getEvents().trigger("Dancing"); + ServiceLocator.getRandomComboService().getEvents().trigger("Dancing"); } else{ ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney"); diff --git a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java index e94e1db4a..6ba9c2818 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java @@ -103,6 +103,7 @@ public static Entity createUpgradeNPC(Vector2 firstPosition, UpgradesDisplay upg // Add a click event listener for the penguin penguin.getEvents().addListener("penguinactivated", ()->{ if (!isClicked[0] && isHoverBox[0] ) { + ServiceLocator.getDocketService().getEvents().trigger("paused"); hoverBox.setEnabled(false); logger.info("Penguin clicked!"); upgradesDisplay.create(); @@ -113,7 +114,9 @@ public static Entity createUpgradeNPC(Vector2 firstPosition, UpgradesDisplay upg } }); - ServiceLocator.getRandomComboService().getEvents().addListener("response", penguin::dispose); + ServiceLocator.getRandomComboService().getEvents().addListener("response", ()->{ + ServiceLocator.getDocketService().getEvents().trigger("unpaused"); + penguin.dispose();}); return penguin; } diff --git a/source/core/src/main/com/csse3200/game/services/RandomComboService.java b/source/core/src/main/com/csse3200/game/services/RandomComboService.java index 3d3939582..9cd9497b4 100644 --- a/source/core/src/main/com/csse3200/game/services/RandomComboService.java +++ b/source/core/src/main/com/csse3200/game/services/RandomComboService.java @@ -38,12 +38,12 @@ public RandomComboService(EventHandler eventHandler) { this.random = new Random(); randomChoice = random.nextInt(total_upgrades); - ServiceLocator.getDocketService().getEvents().addListener("Dancing", ()->{ - isDancing = true; - }); - ServiceLocator.getDocketService().getEvents().addListener("UnDancing", ()->{ - isDancing = false; - }); + eventHandler.addListener("Dancing", ()->{isDancing = true;}); + eventHandler.addListener("UnDancing", ()->{isDancing = true;}); + + // ServiceLocator.getDocketService().getEvents().addListener("UnDancing", ()->{ + // isDancing = false; + // }); } /** From 40ac364c04c03541cb025a431320d1a17a9475fd Mon Sep 17 00:00:00 2001 From: daleelakhairil Date: Thu, 17 Oct 2024 01:50:05 +1000 Subject: [PATCH 21/29] fixed bug for recipe card #630 --- .../game/components/ordersystem/MainGameOrderTicketDisplay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java index 83b9ee43d..3005d9350 100644 --- a/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java +++ b/source/core/src/main/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplay.java @@ -167,7 +167,7 @@ public boolean keyDown(InputEvent event, int keycode) { * @return true if the ESCAPE key was pressed and the event was handled, false otherwise. */ public boolean handleKeyDown(int keycode) { - if (keycode == com.badlogic.gdx.Input.Keys.ESCAPE) { + if (keycode == com.badlogic.gdx.Input.Keys.ESCAPE || keycode == Input.Keys.NUM_0) { setPaused(!isPaused); return true; } From 3184f4c4bd28072f6d297510140da3d6a33e6653 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 03:00:29 +1000 Subject: [PATCH 22/29] Fixed MainGameOrderTicketDisplayTest.java setup to accomodate bug fix for dance party upgrade --- .../ordersystem/MainGameOrderTicketDisplayTest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java b/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java index 56d0cd24f..b793b309f 100644 --- a/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java +++ b/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java @@ -13,10 +13,7 @@ import com.csse3200.game.events.EventHandler; import com.csse3200.game.extensions.GameExtension; import com.csse3200.game.rendering.RenderService; -import com.csse3200.game.services.DocketService; -import com.csse3200.game.services.PlayerService; -import com.csse3200.game.services.ResourceService; -import com.csse3200.game.services.ServiceLocator; +import com.csse3200.game.services.*; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -51,6 +48,7 @@ class MainGameOrderTicketDisplayTest { @Mock Texture textureMock; MainGameOrderTicketDisplay orderTicketDisplay; @Mock CombatStatsComponent combatStatsComponent; + RandomComboService randomComboService; private static final Logger logger = LoggerFactory.getLogger(MainGameOrderTicketDisplayTest.class); /** @@ -64,6 +62,9 @@ void setUp() { resourceService = mock(ResourceService.class); ServiceLocator.registerResourceService(resourceService); textureMock = mock(Texture.class); + randomComboService = new RandomComboService(new EventHandler()); + + ServiceLocator.registerRandomComboService(randomComboService); lenient().when(resourceService.getAsset("images/ordersystem/acai_bowl_docket.png", Texture.class)).thenReturn(textureMock); lenient().when(resourceService.getAsset("images/ordersystem/steak_meal_docket.png", Texture.class)).thenReturn(textureMock); From d75a4c3ec8eae5bdeee7d03361cf9ded5fa23417 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 05:49:55 +1000 Subject: [PATCH 23/29] Setup testing for extortion --- .../components/upgrades/ExtortionUpgrade.java | 59 +++++++---- .../upgrades/DancePartyUpgradeTest.java | 1 - .../upgrades/ExtortionUpgradeTest.java | 100 ++++++++++++------ 3 files changed, 106 insertions(+), 54 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java index a59bb39a6..4cda15fb6 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java @@ -29,9 +29,9 @@ public class ExtortionUpgrade extends UIComponent implements Upgrade { private static final String[] greenTexture = {"images/green_fill.png"}; private static final String[] whiteBgTexture = {"images/white_background.png"}; - private Table layout; - private Label text; // the "Upgrade" text above the speedMeter - private ProgressBar meter; // the meter that show the remaining time + public Table layout; + public Label text; // the "Upgrade" text above the meter + public ProgressBar meter; // the meter that show the remaining time private boolean isVisible; private Sound bgEffect; private boolean playSound = false; @@ -49,6 +49,14 @@ public ExtortionUpgrade() { ServiceLocator.getRandomComboService().getEvents().addListener("Extortionoff", this::deactivate); } + public ExtortionUpgrade(CombatStatsComponent combatStatsComponent) { + this.isActive = false; + this.gameTime = ServiceLocator.getTimeSource(); + this.combatStatsComponent = combatStatsComponent; + ServiceLocator.getRandomComboService().getEvents().addListener("Extortion", this::activate); + ServiceLocator.getRandomComboService().getEvents().addListener("Extortionoff", this::deactivate); + } + @Override public void create() { super.create(); @@ -61,7 +69,7 @@ public void create() { layout = new Table(); layout.setFillParent(true); layout.setVisible(isVisible); - setupMeter(); +// setupMeter(); } /** @@ -69,31 +77,37 @@ public void create() { * Also initializes the accompanying label. */ private void setupMeter() { - if (meter == null) { - Texture whiteBgTexture = ServiceLocator.getResourceService().getAsset("images/white_background.png", Texture.class); - Texture fillTexture = ServiceLocator.getResourceService().getAsset("images/green_fill.png", Texture.class); + Texture whiteBgTexture = ServiceLocator + .getResourceService().getAsset("images/white_background.png", Texture.class); + Texture fillTexture = ServiceLocator + .getResourceService().getAsset("images/green_fill.png", Texture.class); + + ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(); - ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(); - style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); - style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); + // Setting white background + style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); + style.background.setMinHeight(15); + style.background.setMinWidth(10); - style.background = new TextureRegionDrawable(new TextureRegion(whiteBgTexture)); - style.background.setMinHeight(15); - style.background.setMinWidth(10); + // Setting green fill color + style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); + style.knobBefore.setMinHeight(15); + style.background.setMinWidth(10); - // Setting green fill color - style.knobBefore = new TextureRegionDrawable(new TextureRegion(fillTexture)); - style.knobBefore.setMinHeight(15); - style.background.setMinWidth(10); + // Only show the speed meter if it is activated + if (isActive) { meter = new ProgressBar(0f, 1f, 0.01f, false, style); - meter.setValue(1f); + meter.setValue(1f); // Initially, the meter is full meter.setPosition(30, 250); - text = new Label("Upgrade", skin); - text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); - layout.add(text).row(); - layout.add(meter); + // Set up text + text = new Label("Upgrade", skin); + text.setPosition(meter.getX(), meter.getY() + meter.getHeight() + 8); // Placed above meter + } + else { + meter = null; + text = null; } } @@ -111,6 +125,7 @@ public void activate() { activateTimeRemaining = upgradeDuration; isVisible = true; layout.setVisible(true); + setupMeter(); } else { ServiceLocator.getRandomComboService().getEvents().trigger("notenoughmoney"); diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index d461703b3..ab6a73a5e 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -41,7 +41,6 @@ public class DancePartyUpgradeTest { @Mock ProgressBar meter; @Mock Label mockText; @Mock CombatStatsComponent combatStatsComponent; - @Mock KeyboardPlayerInputComponent keyboardPlayerInputComponent; private EventHandler randomComboEventHandler; private EventHandler docketEventHandler; RandomComboService randomComboService; diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java index 7371dd2e0..7282efb2f 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java @@ -1,52 +1,90 @@ package com.csse3200.game.components.upgrades; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.*; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.utils.viewport.Viewport; import com.csse3200.game.components.CombatStatsComponent; -import com.csse3200.game.components.ordersystem.MainGameOrderTicketDisplay; +import com.csse3200.game.components.player.KeyboardPlayerInputComponent; import com.csse3200.game.events.EventHandler; -import com.csse3200.game.services.GameTime; -import com.csse3200.game.services.PlayerService; -import com.csse3200.game.services.ServiceLocator; -import net.dermetfan.gdx.physics.box2d.PositionController; +import com.csse3200.game.extensions.GameExtension; +import com.csse3200.game.rendering.RenderService; +import com.csse3200.game.services.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.*; + +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.concurrent.atomic.AtomicBoolean; +@ExtendWith(GameExtension.class) +@ExtendWith(MockitoExtension.class) public class ExtortionUpgradeTest { - /** - private CombatStatsComponent combatStatsComponent; + @Mock RenderService renderService; + @Spy OrthographicCamera camera; + @Mock Stage stage; + @Mock Viewport viewport; + @Mock ResourceService resourceService; + @Mock GameTime gameTime; + @Mock Texture textureMock; + @Mock Table mockLayout; + @Mock ProgressBar mockSpeedMeter; + @Mock Label mockText; + @Mock CombatStatsComponent combatStatsComponent; + @Mock KeyboardPlayerInputComponent keyboardPlayerInputComponent; + private EventHandler eventHandler; + RandomComboService randomComboService; private ExtortionUpgrade extortionUpgrade; - private MainGameOrderTicketDisplay mainGameOrderTicketDisplay; - @BeforeEach - void beforeEach() { - GameTime gameTime = mock(GameTime.class); - when(gameTime.getTime()).thenReturn(0L); - ServiceLocator.registerTimeSource(gameTime); + void setUp() { + ServiceLocator.clear(); - PlayerService playerService = new PlayerService(); - ServiceLocator.registerPlayerService(playerService); + eventHandler = new EventHandler(); + randomComboService = new RandomComboService(eventHandler); - //To my knowledge you can't do when() on this, which is causing a lot of problems - //when(ServiceLocator.getPlayerService()).thenReturn(new PlayerService()); + ServiceLocator.registerRandomComboService(randomComboService); + ServiceLocator.registerRenderService(renderService); + ServiceLocator.registerResourceService(resourceService); + ServiceLocator.registerTimeSource(gameTime); - //extortionUpgrade = mock(new ExtortionUpgrade(10, gameTime)); - extortionUpgrade = mock(ExtortionUpgrade.class); - mainGameOrderTicketDisplay = new MainGameOrderTicketDisplay(); - when(extortionUpgrade.getTickets()).thenReturn(mainGameOrderTicketDisplay); + lenient().when(resourceService.getAsset(anyString(), eq(Texture.class))).thenReturn(textureMock); + lenient().when(renderService.getStage()).thenReturn(stage); + lenient().when(renderService.getStage().getViewport()).thenReturn(viewport); + lenient().when(renderService.getStage().getViewport().getCamera()).thenReturn(camera); - //TODO mock CombatStatsService + extortionUpgrade = new ExtortionUpgrade(combatStatsComponent); + extortionUpgrade.setStage(stage); + extortionUpgrade.layout = mockLayout; + extortionUpgrade.meter = mockSpeedMeter; + extortionUpgrade.text = mockText; + extortionUpgrade.create(); } @Test - void shouldDoubleGold() { - int goldBefore = mainGameOrderTicketDisplay.getRecipeValue(); - int goldAfter = mainGameOrderTicketDisplay.getRecipeValue(); - assertEquals(goldBefore, goldAfter); + void testNotNull() { + assertNotNull(extortionUpgrade); + } + + @Test + void testDispose() { + extortionUpgrade.dispose(); + verify(resourceService).unloadAssets(SpeedBootsUpgrade.whiteBgTexture); + verify(resourceService).unloadAssets(SpeedBootsUpgrade.greenTexture); + } + + @AfterEach + void tearDown() { + ServiceLocator.clear(); } - */ } From b8f6a1cafb5e968e3f3880743a6fd8882f3a9c54 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 06:00:07 +1000 Subject: [PATCH 24/29] Added test for extortion upgrade activation --- .../components/upgrades/ExtortionUpgrade.java | 20 +++++++++++++++---- .../upgrades/ExtortionUpgradeTest.java | 18 +++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java index 4cda15fb6..d4a21d370 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java @@ -148,10 +148,6 @@ public void deactivate() { text.remove(); } - public boolean isActive() { - return isActive; - } - /** * checks to see if the duration of ugprade has ended and consequently deactivates */ @@ -196,6 +192,22 @@ protected void draw(SpriteBatch batch) { @Override public void setStage(Stage mock) { + this.stage = mock; + } + + public boolean isActive() { + return isActive; + } + + public boolean isVisible() { + return isVisible; + } + + public long getUpgradeDuration() { + return upgradeDuration; + } + public float getActivateTimeRemaining() { + return activateTimeRemaining; } } \ No newline at end of file diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java index 7282efb2f..763cc58c9 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java @@ -41,7 +41,6 @@ public class ExtortionUpgradeTest { @Mock ProgressBar mockSpeedMeter; @Mock Label mockText; @Mock CombatStatsComponent combatStatsComponent; - @Mock KeyboardPlayerInputComponent keyboardPlayerInputComponent; private EventHandler eventHandler; RandomComboService randomComboService; private ExtortionUpgrade extortionUpgrade; @@ -72,8 +71,23 @@ void setUp() { } @Test - void testNotNull() { + void testSpeedBootsActivates() { assertNotNull(extortionUpgrade); + when(combatStatsComponent.getGold()).thenReturn(100); + extortionUpgrade.activate(); + + AtomicBoolean isActive = new AtomicBoolean(false); + eventHandler.addListener("extortion active", () -> { + isActive.set(true); + }); + eventHandler.trigger("extortion active"); + + assertTrue(isActive.get()); + assertTrue(extortionUpgrade.isActive()); + assertTrue(extortionUpgrade.isVisible()); + assertTrue(extortionUpgrade.layout.isVisible()); + assertEquals(extortionUpgrade.getUpgradeDuration(), extortionUpgrade.getActivateTimeRemaining()); + assertEquals(1f, extortionUpgrade.meter.getValue()); } @Test From fd09996a7b5d891a46442d6b0877c0f1880e2d4f Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 06:06:14 +1000 Subject: [PATCH 25/29] Added testing for extortion upgrade deactivation --- .../upgrades/ExtortionUpgradeTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java index 763cc58c9..b7f350581 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java @@ -90,6 +90,28 @@ void testSpeedBootsActivates() { assertEquals(1f, extortionUpgrade.meter.getValue()); } + @Test + void testSpeedBootsDeactivates() { + extortionUpgrade.activate(); + lenient().when(mockSpeedMeter.hasParent()).thenReturn(true); + extortionUpgrade.deactivate(); + + AtomicBoolean isActive = new AtomicBoolean(false); + eventHandler.addListener("UnDancing", () -> { + isActive.set(true); + }); + eventHandler.trigger("UnDancing"); + + assertTrue(isActive.get()); + verify(extortionUpgrade.meter).remove(); + verify(extortionUpgrade.text).remove(); + + assertFalse(extortionUpgrade.isActive()); + assertFalse(extortionUpgrade.isVisible()); + assertFalse(extortionUpgrade.layout.isVisible()); + assertEquals(0f, extortionUpgrade.meter.getValue()); + } + @Test void testDispose() { extortionUpgrade.dispose(); From 06d13bce8229d72018ce5c961666222c42611edc Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 06:09:50 +1000 Subject: [PATCH 26/29] Added tests for extortion and gold behavior --- .../upgrades/ExtortionUpgradeTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java index b7f350581..d5ee027c6 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java @@ -112,6 +112,29 @@ void testSpeedBootsDeactivates() { assertEquals(0f, extortionUpgrade.meter.getValue()); } + @Test + void testLoseGoldOnPurchase() { + when(combatStatsComponent.getGold()).thenReturn(100); + extortionUpgrade.activate(); + verify(combatStatsComponent).addGold(-40); + } + + @Test + void testInsufficientGold() { + when(combatStatsComponent.getGold()).thenReturn(10); + AtomicBoolean notEnoughMoney = new AtomicBoolean(false); + eventHandler.addListener("notenoughmoney", () -> { + notEnoughMoney.set(true); + }); + + extortionUpgrade.activate(); + + assertTrue(notEnoughMoney.get()); + assertFalse(extortionUpgrade.isActive()); + assertFalse(extortionUpgrade.isVisible()); + assertFalse(extortionUpgrade.layout.isVisible()); + } + @Test void testDispose() { extortionUpgrade.dispose(); From 2d58ad9cae394a84294f098e239d05b5693d140c Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 06:14:08 +1000 Subject: [PATCH 27/29] Tested extortion upgrade for 30 seconds --- .../components/upgrades/ExtortionUpgrade.java | 4 +++ .../upgrades/ExtortionUpgradeTest.java | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java index d4a21d370..bd3543ffc 100644 --- a/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java +++ b/source/core/src/main/com/csse3200/game/components/upgrades/ExtortionUpgrade.java @@ -210,4 +210,8 @@ public long getUpgradeDuration() { public float getActivateTimeRemaining() { return activateTimeRemaining; } + + public boolean getPlaySound() { + return playSound; + } } \ No newline at end of file diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java index d5ee027c6..9f787ecbb 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java @@ -71,7 +71,7 @@ void setUp() { } @Test - void testSpeedBootsActivates() { + void testExtortionUpgradeActivates() { assertNotNull(extortionUpgrade); when(combatStatsComponent.getGold()).thenReturn(100); extortionUpgrade.activate(); @@ -91,7 +91,7 @@ void testSpeedBootsActivates() { } @Test - void testSpeedBootsDeactivates() { + void testExtortionUpgradeDeactivates() { extortionUpgrade.activate(); lenient().when(mockSpeedMeter.hasParent()).thenReturn(true); extortionUpgrade.deactivate(); @@ -135,6 +135,28 @@ void testInsufficientGold() { assertFalse(extortionUpgrade.layout.isVisible()); } + @Test + void testExtortionUpgradeFor30Seconds() { + ExtortionUpgrade spyExtortionUpgrade = spy(extortionUpgrade); + when(combatStatsComponent.getGold()).thenReturn(100); + spyExtortionUpgrade.activate(); + + when(gameTime.getDeltaTime()).thenReturn(1f); + for (int i = 0; i < 15; i++) { + spyExtortionUpgrade.update(); + } + + assertEquals(spyExtortionUpgrade.getActivateTimeRemaining() / + (float) spyExtortionUpgrade.getUpgradeDuration(), spyExtortionUpgrade.meter.getValue()); + + for (int i = 0; i < 15; i++) { + spyExtortionUpgrade.update(); + } + + verify(spyExtortionUpgrade).deactivate(); + assertFalse(spyExtortionUpgrade.getPlaySound()); + } + @Test void testDispose() { extortionUpgrade.dispose(); From 9b7b2647aa2e8904af7d5d8b62d7b1d39f5caa25 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 06:16:32 +1000 Subject: [PATCH 28/29] Added parameterized tests for testing extortion depletion at different depletion levels --- .../upgrades/ExtortionUpgradeTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java index 9f787ecbb..b4a6b9544 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/ExtortionUpgradeTest.java @@ -157,6 +157,22 @@ void testExtortionUpgradeFor30Seconds() { assertFalse(spyExtortionUpgrade.getPlaySound()); } + @ParameterizedTest + @ValueSource(ints = {5, 10, 15, 20, 25, 30}) + void testMeterValueAtDifferentLevelsOfDepletion(int totalDepletedTime) { + ExtortionUpgrade spyExtortionUpgrade = spy(extortionUpgrade); + when(combatStatsComponent.getGold()).thenReturn(100); + spyExtortionUpgrade.activate(); + + when(gameTime.getDeltaTime()).thenReturn(1f); + for (int i = 0; i < totalDepletedTime; i++) { + spyExtortionUpgrade.update(); + } + + assertEquals(spyExtortionUpgrade.getActivateTimeRemaining() / + (float) spyExtortionUpgrade.getUpgradeDuration(), spyExtortionUpgrade.meter.getValue(), 0.01); + } + @Test void testDispose() { extortionUpgrade.dispose(); From bebb58d2d6f15cab9e2be4b06fed9e54327e8655 Mon Sep 17 00:00:00 2001 From: degr8pheonix Date: Thu, 17 Oct 2024 08:31:36 +1000 Subject: [PATCH 29/29] Added Random Combo Service to the new mocked ServiceLocator in MainGameOrderTicketDisplayTest.java. It wasn't before, which was causing the test's to fail. --- .../components/ordersystem/MainGameOrderTicketDisplayTest.java | 3 +-- .../game/components/upgrades/DancePartyUpgradeTest.java | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java b/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java index 30e5f867e..7c319fcd2 100644 --- a/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java +++ b/source/core/src/test/com/csse3200/game/components/ordersystem/MainGameOrderTicketDisplayTest.java @@ -69,8 +69,6 @@ void setUp() { textureMock = mock(Texture.class); randomComboService = new RandomComboService(new EventHandler()); - ServiceLocator.registerRandomComboService(randomComboService); - serviceLocatorMock = Mockito.mockStatic(ServiceLocator.class); serviceLocatorMock.when(ServiceLocator::getRenderService).thenReturn(renderService); @@ -78,6 +76,7 @@ void setUp() { serviceLocatorMock.when(ServiceLocator::getPlayerService).thenReturn(playerService); serviceLocatorMock.when(ServiceLocator::getResourceService).thenReturn(resourceService); serviceLocatorMock.when(ServiceLocator::getTicketDetails).thenReturn(ticketDetails); + serviceLocatorMock.when(ServiceLocator::getRandomComboService).thenReturn(randomComboService); resourceService = mock(ResourceService.class); textureMock = mock(Texture.class); diff --git a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java index bb62a2726..ab6a73a5e 100644 --- a/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java +++ b/source/core/src/test/com/csse3200/game/components/upgrades/DancePartyUpgradeTest.java @@ -25,6 +25,8 @@ import org.junit.jupiter.api.Test; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.concurrent.atomic.AtomicBoolean; + @ExtendWith(GameExtension.class) @ExtendWith(MockitoExtension.class) public class DancePartyUpgradeTest {