diff --git a/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java index b3c15e9c2..e1e0a76b7 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java @@ -105,27 +105,13 @@ public void updateTowerState() { } switch (towerState) { - case WALK -> { - handleWalkState(); - } - case IDLE -> { - handleIdleState(); - } - case SHOOT_DOWN -> { - handleShootDownState(); - } - case SHOOT_UP -> { - handleShootUpState(); - } - case DOWN -> { - handleDownState(); - } - case UP -> { - handleUpState(); - } - default -> { // DIE - handleDieState(); - } + case WALK -> handleWalkState(); + case IDLE -> handleIdleState(); + case SHOOT_DOWN -> handleShootDownState(); + case SHOOT_UP -> handleShootUpState(); + case DOWN -> handleDownState(); + case UP -> handleUpState(); + default -> handleDieState(); // DIE } } @@ -138,6 +124,10 @@ public STATE getState() { return this.towerState; } + /** + * Function for setting the tower's state. + * @param state The new state of this tower. + */ public void setState(STATE state) { this.towerState = state; } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/FireTowerCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/FireTowerCombatTask.java index 60714c560..7e4cb7a3b 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/FireTowerCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/FireTowerCombatTask.java @@ -101,18 +101,10 @@ public void updateTowerState() { } switch (towerState) { - case IDLE -> { - handleIdleState(); - } - case PREP_ATTACK -> { - handlePrepAttackState(); - } - case ATTACK -> { - handleAttackState(); - } - default -> { // DEATH - handleDeathState(); - } + case IDLE -> handleIdleState(); + case PREP_ATTACK -> handlePrepAttackState(); + case ATTACK -> handleAttackState(); + default -> handleDeathState(); // DEATH } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java index b5dd8f45c..f9ad1cb60 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/TowerCombatTask.java @@ -57,7 +57,6 @@ private enum STATE { * @param maxRange Maximum effective range of the weapon tower. This determines the detection distance of targets */ public TowerCombatTask(int priority, float maxRange) { - this.priority = priority; this.maxRange = maxRange; this.fireRateInterval = 1; @@ -182,7 +181,7 @@ private boolean isTargetVisible() { * @param newInterval The rate at which the tower should fire projectiles in shots per second. */ private void changeFireRateInterval(int newInterval) { - logger.info("Changing fire rate to: %d", newInterval); + logger.info(String.format("Changing fire rate to: %d", newInterval)); fireRateInterval = 1 / ((float) newInterval / 5); } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/WallTowerDestructionTask.java b/source/core/src/main/com/csse3200/game/components/tasks/WallTowerDestructionTask.java index 749647851..1e2f3ff90 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/WallTowerDestructionTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/WallTowerDestructionTask.java @@ -4,8 +4,6 @@ import com.csse3200.game.ai.tasks.DefaultTask; import com.csse3200.game.ai.tasks.PriorityTask; import com.csse3200.game.components.CombatStatsComponent; -import com.csse3200.game.entities.Entity; -import com.csse3200.game.entities.factories.ProjectileFactory; import com.csse3200.game.physics.PhysicsEngine; import com.csse3200.game.physics.PhysicsLayer; import com.csse3200.game.physics.raycast.RaycastHit; @@ -43,7 +41,7 @@ public class WallTowerDestructionTask extends DefaultTask implements PriorityTas public enum STATE { IDLE, DEATH } - public STATE towerState = STATE.IDLE; + private STATE towerState = STATE.IDLE; /** * @param priority Task priority when targets are detected (0 when nothing is present) @@ -75,6 +73,7 @@ public void start() { * updates the current state of the tower based on the current state of the game. If enemies are detected, attack * state is activated and otherwise idle state remains. */ + @Override public void update() { if (timeSource.getTime() >= endTime) { updateTowerState(); @@ -87,22 +86,19 @@ public void update() { * of the game. If enemies are detected, state of the tower is changed to attack state. */ public void updateTowerState() { - if (owner.getEntity().getComponent(CombatStatsComponent.class).getHealth() <= 0 && towerState != STATE.DEATH) { owner.getEntity().getEvents().trigger(DEATH); towerState = STATE.DEATH; return; } - switch (towerState) { - case IDLE -> { - owner.getEntity().getEvents().trigger(IDLE); - towerState = STATE.IDLE; - } - case DEATH -> { - if (owner.getEntity().getComponent(AnimationRenderComponent.class).isFinished()) { - owner.getEntity().setFlagForDelete(true); - } + // Replace "switch" statement by "if" statements to increase readability. + if (towerState == STATE.IDLE) { + owner.getEntity().getEvents().trigger(IDLE); + towerState = STATE.IDLE; + } else { // DEATH + if (owner.getEntity().getComponent(AnimationRenderComponent.class).isFinished()) { + owner.getEntity().setFlagForDelete(true); } } } @@ -115,9 +111,18 @@ public STATE getState() { return this.towerState; } + /** + * Function for setting the tower's state. + * @param newState The new state of this tower. + */ + public void setState(STATE newState) { + this.towerState = newState; + } + /** * stops the current animation and switches back the state of the tower to IDLE. */ + @Override public void stop() { super.stop(); owner.getEntity().getEvents().trigger(IDLE); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipCombatTask.java index 0c044d89f..3dd7a3124 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipCombatTask.java @@ -4,28 +4,18 @@ import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.DefaultTask; import com.csse3200.game.ai.tasks.PriorityTask; -import com.csse3200.game.entities.Entity; -import com.csse3200.game.entities.factories.ProjectileFactory; import com.csse3200.game.physics.PhysicsEngine; -import com.csse3200.game.physics.PhysicsLayer; -import com.csse3200.game.physics.raycast.RaycastHit; import com.csse3200.game.services.GameTime; import com.csse3200.game.services.ServiceLocator; - -import java.util.ArrayList; - /** * The AI Task for the Engineer entity. The Engineer will scan for targets within its detection range * and trigger events to change its state accordingly. This task must be called once the Engineer has * appropiately moved into position. */ public class BombshipCombatTask extends DefaultTask implements PriorityTask { - private static final int INTERVAL = 1; // The time interval for each target scan from the Engineer. private static final int PRIORITY = 3; // Default priority of the combat task when mobs are in range. - private static final short TARGET1 = PhysicsLayer.BOSS; // The type of targets that the Engineer will detect. - private static final short TARGET2 = PhysicsLayer.XENO; // Animation event names for the Engineer's state machine. private static final String START = "start"; @@ -34,18 +24,11 @@ public class BombshipCombatTask extends DefaultTask implements PriorityTask { // The Engineer's attributes. private final float maxRange; // The maximum range of the bombship. - - private Vector2 bombShipPosition = new Vector2(0, 0); // Placeholder value for the Bombship's position. private final Vector2 maxRangePosition = new Vector2(); private PhysicsEngine physics; private GameTime timeSource; private long endTime; - private long reloadTime; -/** - private ArrayList hits = new ArrayList<>(); - private final RaycastHit hit = new RaycastHit(); - private ArrayList targets = new ArrayList<>(); -*/ + /** The Engineer's states. */ private enum STATE { IDLE, START , DESTROY @@ -64,8 +47,11 @@ public BombshipCombatTask(float maxRange) { @Override public void start() { super.start(); - this.bombShipPosition = owner.getEntity().getCenterPosition(); + + // Placeholder value for the Bombship's position. + Vector2 bombShipPosition = owner.getEntity().getCenterPosition(); this.maxRangePosition.set(bombShipPosition.x + maxRange, bombShipPosition.y); + // Default to idle mode owner.getEntity().getEvents().trigger(IDLE); endTime = timeSource.getTime() + (INTERVAL * 500); @@ -104,9 +90,7 @@ public void updateBombshipState() { owner.getEntity().getEvents().trigger(START); } } - case DESTROY -> { - owner.getEntity().getEvents().trigger(DESTROY); - } + default -> owner.getEntity().getEvents().trigger(DESTROY); // DESTROY } } @@ -117,13 +101,6 @@ private void combatState() { owner.getEntity().getEvents().trigger(START); bombshipState = STATE.START; } - /** - * For stopping the running task - */ - @Override - public void stop() { - super.stop(); - } /** * Simplified getPriority function, returns the priority of the task @@ -141,32 +118,7 @@ public int getPriority() { * @return true if a target is detected, false otherwise */ public boolean isEngineerDied() { - //if (engineerCount < maxEngineers) { - return true; - //} - } - - /** - * Fetches the nearest target from the array of detected target positions created during the last call of - * this could be done in the next sprint , the scan doesnt work as of now ! - * @return a Vector2 position of the nearest mob detected. - */ - /** public Vector2 fetchTarget() { - // Initial nearest position for comparison - int lowest = 10; - - Vector2 nearest = new Vector2(owner.getEntity().getCenterPosition().x, - owner.getEntity().getCenterPosition().y); - - // Find the nearest target from the array of targets - for (Vector2 tgt : targets){ - if (Math.abs(tgt.y - nearest.y) < lowest) { - lowest = (int)Math.abs(tgt.y - nearest.y); - nearest = tgt; - } - } - return nearest; + return true; } - */ } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipWanderTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipWanderTask.java index 63c611885..faf62ba6c 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipWanderTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bombship/BombshipWanderTask.java @@ -4,12 +4,10 @@ import com.csse3200.game.ai.tasks.DefaultTask; import com.csse3200.game.ai.tasks.PriorityTask; import com.csse3200.game.ai.tasks.Task; -import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.physics.PhysicsLayer; import com.csse3200.game.physics.components.ColliderComponent; import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.rendering.AnimationRenderComponent; -import com.csse3200.game.services.ServiceLocator; /** * BombshipWanderTask is the entry point for the engineer entity's behaviour. Instantiates subtasks HumanWaitTask, @@ -17,7 +15,6 @@ * handled in this class. */ public class BombshipWanderTask extends DefaultTask implements PriorityTask { - private static final int TOLERANCE = 1; private static final float STOP_DISTANCE = 0.5f; private static final int DEFAULT_PRIORITY = 1; private static final String START = "start"; @@ -85,28 +82,18 @@ public void start() { */ @Override public void update() { - if (!isDestroyed) { - startDestroying(); - } - // Check if bombship has destroyed since last update if (!isDestroyed) { - startDestroying(); - } else if (isDestroyed && animator.isFinished()) { - owner.getEntity().setFlagForDelete(true); - } - - // otherwise doing engineer things since engineer is alive - else if (!isDestroyed){ doBombshipThings(); - + startDestroying();; currentTask.update(); + } else if (isDestroyed && animator.isFinished()) { + owner.getEntity().setFlagForDelete(true); } } private void doBombshipThings() { if (currentTask.getStatus() != Status.ACTIVE) { - // if the engineer is in move state and update has been called, engineer has arrived at destination if (currentTask == movementTask) { startWaiting(); @@ -117,6 +104,7 @@ private void doBombshipThings() { } } } + /** * Handle the dying phase of the entity. Triggers an event to play the appropriate media, * sets HitBox and Collider components to ignore contact (stops the body being pushed around) @@ -137,22 +125,6 @@ private void startWaiting() { swapTask(waitTask); } - /** - * Starts the movement task, to a particular destination - * @param destination the Vector2 position to which the entity needs to move - */ - private void startMoving(Vector2 destination) { - movementTask.setTarget(destination); - swapTask(movementTask); - } - - /** - * Starts the combat task. - */ - private void startCombat() { - swapTask(combatTask); - } - /** * Allows manual switching of tasks, from the current task to the supplied newTask. * @param newTask the task being switched to. @@ -161,6 +133,7 @@ private void swapTask(Task newTask) { if (currentTask != null) { currentTask.stop(); } + currentTask = newTask; currentTask.start(); } diff --git a/source/core/src/main/com/csse3200/game/components/tower/FireTowerAnimationController.java b/source/core/src/main/com/csse3200/game/components/tower/FireTowerAnimationController.java index b370365d1..a2cd29c89 100644 --- a/source/core/src/main/com/csse3200/game/components/tower/FireTowerAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/tower/FireTowerAnimationController.java @@ -21,7 +21,6 @@ public class FireTowerAnimationController extends Component{ private static final String PREP_ATTACK_ANIM = "prepAttack"; private static final String ATTACK_ANIM = "attack"; private static final String DEATH_ANIM = "death"; - //here we can add the sounds for the implemented animations private static final String FIRE_SINGLE_SFX = "sounds/towers/Desert-Eagle-Far-Single-Gunshot.mp3"; diff --git a/source/core/src/main/com/csse3200/game/components/tower/StunTowerAnimationController.java b/source/core/src/main/com/csse3200/game/components/tower/StunTowerAnimationController.java index d3eaec777..1fc59068a 100644 --- a/source/core/src/main/com/csse3200/game/components/tower/StunTowerAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/tower/StunTowerAnimationController.java @@ -18,8 +18,6 @@ public class StunTowerAnimationController extends Component { private static final String ATTACK_ANIM = "attack"; private static final String DEATH_ANIM = "death"; - //further sounds can be added for the tower attacks/movement - private static final String FIRE_SINGLE_SFX = "sounds/towers/ar15_single_shot_far.mp3"; private final Sound fireSingleSound = ServiceLocator.getResourceService().getAsset( diff --git a/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java b/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java index 4394d6309..a7d07d076 100644 --- a/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java +++ b/source/core/src/main/com/csse3200/game/components/tower/TowerUpgraderComponent.java @@ -38,7 +38,6 @@ public void upgradeTower(UPGRADE upgradeType, int value) { case MAXHP -> upgradeTowerMaxHealth( value); case FIRERATE -> getEntity().getEvents().trigger("addFireRate", value); case REPAIR -> repairTower(); - } } diff --git a/source/core/src/main/com/csse3200/game/components/tower/WallTowerAnimationController.java b/source/core/src/main/com/csse3200/game/components/tower/WallTowerAnimationController.java index 4f22bfaf5..69624ad41 100644 --- a/source/core/src/main/com/csse3200/game/components/tower/WallTowerAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/tower/WallTowerAnimationController.java @@ -14,7 +14,7 @@ public class WallTowerAnimationController extends Component{ //animation name constants private static final String DEATH_ANIM = "Death"; - private static final String Idle_ANIM = "Idle"; + private static final String IDLE_ANIM = "Idle"; //here we can add the sounds for the implemented animations AnimationRenderComponent animator; @@ -29,13 +29,15 @@ public void create() { entity.getEvents().addListener(DEATH, this::animateDeath); entity.getEvents().addListener(IDLE, this::animateIdle); } + /** * Starts the idle animation. */ void animateDeath() { animator.startAnimation(DEATH_ANIM); } + void animateIdle(){ - animator.startAnimation(Idle_ANIM); + animator.startAnimation(IDLE_ANIM); } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/BaseTowerConfigs.java b/source/core/src/main/com/csse3200/game/entities/configs/BaseTowerConfigs.java new file mode 100644 index 000000000..03530fef3 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/entities/configs/BaseTowerConfigs.java @@ -0,0 +1,105 @@ +package com.csse3200.game.entities.configs; + +/** + * Defines all tower configs to be loaded by the Tower Factory. + */ +public class BaseTowerConfigs { + private WeaponTowerConfig weapon = new WeaponTowerConfig(); + private WallTowerConfig wall = new WallTowerConfig(); + private IncomeTowerConfig income = new IncomeTowerConfig(); + private FireTowerConfig fireTower = new FireTowerConfig(); + private StunTowerConfig stunTower = new StunTowerConfig(); + private TNTTowerConfigs TNTTower = new TNTTowerConfigs(); + private DroidTowerConfig DroidTower = new DroidTowerConfig(); + private FireworksTowerConfig fireworksTower = new FireworksTowerConfig(); + private PierceTowerConfig pierceTower = new PierceTowerConfig(); + private RicochetTowerConfig ricochetTower = new RicochetTowerConfig(); + private HealTowerConfig healTower = new HealTowerConfig(); + + /** + * Function for getting the wall tower's config + * @return The config of wall tower + */ + public WallTowerConfig getWall() { + return wall; + } + + /** + * Function for getting the weapon tower's config + * @return The config of weapon tower + */ + public WeaponTowerConfig getWeapon() { + return weapon; + } + + /** + * Function for getting the income tower's config + * @return The config of income tower + */ + public IncomeTowerConfig getIncome() { + return income; + } + + /** + * Function for getting the fire tower's config + * @return The config of fire tower + */ + public FireTowerConfig getFireTower() { + return fireTower; + } + + /** + * Function for getting the stun tower's config + * @return The config of stun tower + */ + public StunTowerConfig getStunTower() { + return stunTower; + } + + /** + * Function for getting the TNT tower's config + * @return The config of TNT tower */ + public TNTTowerConfigs getTNTTower() { + return TNTTower; + } + + /** + * Function for getting the droid tower's config + * @return The config of droid tower + */ + public DroidTowerConfig getDroidTower() { + return DroidTower; + } + + /** + * Function for getting the fireworks tower's config + * @return The config of fireworks tower + */ + public FireworksTowerConfig getFireworksTower() { + return fireworksTower; + } + + /** + * Function for getting the pierce tower's config + * @return The config of pierce tower + */ + public PierceTowerConfig getPierceTower() { + return pierceTower; + } + + /** + * Function for getting the ricochet tower's config + * @return The config of ricochet tower + */ + public RicochetTowerConfig getRicochetTower() { + return ricochetTower; + } + + /** + * Function for getting the heal tower's config + * @return The config of heal tower + */ + public HealTowerConfig getHealTower() { + return healTower; + } +} \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/entities/configs/DroidTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/DroidTowerConfig.java index 3349a149c..804e72d7d 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/DroidTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/DroidTowerConfig.java @@ -4,9 +4,40 @@ * Defines a basic set of properties stored in entities config files to be loaded by Entity Factories. */ public class DroidTowerConfig { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + private float attackRate = 1; - public float attackRate = 1; + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/FireTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/FireTowerConfig.java index cc5b75284..48af9db9d 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/FireTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/FireTowerConfig.java @@ -1,9 +1,40 @@ package com.csse3200.game.entities.configs; public class FireTowerConfig { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + private float attackRate = 1; - public float attackRate = 1; + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java index d01f0b5c8..dd345afae 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/FireworksTowerConfig.java @@ -1,9 +1,49 @@ package com.csse3200.game.entities.configs; public class FireworksTowerConfig { - public int health = 1; - public int baseAttack = 1; - public int cost = 1; - public int attackRate =1; - public int incomeRate =0; + private int health = 1; + private int baseAttack = 1; + private int cost = 1; + private int attackRate = 1; + private int incomeRate = 0; + + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public int getAttackRate() { + return this.attackRate; + } + + /** + * Function for getting tower's income rate + * @return The income rate of this tower + */ + public int getIncomeRate() { + return this.incomeRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/HealTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/HealTowerConfig.java index 0eb826bcc..c3e5c6f22 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/HealTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/HealTowerConfig.java @@ -1,8 +1,31 @@ package com.csse3200.game.entities.configs; public class HealTowerConfig { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; - //comment to commit message + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/IncomeTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/IncomeTowerConfig.java index bdcf77c06..d065123dc 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/IncomeTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/IncomeTowerConfig.java @@ -4,11 +4,49 @@ * Defines a basic set of properties stored in entities config files to be loaded by Entity Factories. */ public class IncomeTowerConfig { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + private float attackRate = 0; + private float incomeRate = 10; - public float attackRate = 0; - public float incomeRate = 10; + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } + + /** + * Function for getting tower's income rate + * @return The income rate of this tower + */ + public float getIncomeRate() { + return this.incomeRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/PierceTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/PierceTowerConfig.java index 0a44bec79..329b226c2 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/PierceTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/PierceTowerConfig.java @@ -1,8 +1,40 @@ package com.csse3200.game.entities.configs; public class PierceTowerConfig { - public int health = 1; - public int baseAttack = 1; - public int cost = 1; - public float attackRate = 1; + private int health = 1; + private int baseAttack = 1; + private int cost = 1; + private float attackRate = 1; + + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Functino for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/RicochetTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/RicochetTowerConfig.java index f86d48569..07946bc4f 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/RicochetTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/RicochetTowerConfig.java @@ -1,8 +1,40 @@ package com.csse3200.game.entities.configs; public class RicochetTowerConfig { - public int health = 1; - public int baseAttack = 1; - public int cost = 1; - public float attackRate = 1; + private int health = 1; + private int baseAttack = 1; + private int cost = 1; + private float attackRate = 1; + + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Functino for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/StunTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/StunTowerConfig.java index adf01c4f4..a84a1bb9e 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/StunTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/StunTowerConfig.java @@ -1,9 +1,40 @@ package com.csse3200.game.entities.configs; public class StunTowerConfig { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + private float attackRate = 1; - public float attackRate = 1; + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/TNTTowerConfigs.java b/source/core/src/main/com/csse3200/game/entities/configs/TNTTowerConfigs.java index 9385fc512..c6d82c1a1 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/TNTTowerConfigs.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/TNTTowerConfigs.java @@ -4,9 +4,40 @@ * Defines a basic set of properties stored in entities config files to be loaded by Entity Factories. */ public class TNTTowerConfigs { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + private float attackRate = 1; - public float attackRate = 1; + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/WallTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/WallTowerConfig.java index 59c830d4f..82d1f00ee 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/WallTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/WallTowerConfig.java @@ -4,9 +4,40 @@ * Defines a basic set of properties stored in entities config files to be loaded by Entity Factories. */ public class WallTowerConfig { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + private float attackRate = 0; - public float attackRate = 0; + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/WeaponTowerConfig.java b/source/core/src/main/com/csse3200/game/entities/configs/WeaponTowerConfig.java index 7f0547769..b1c123f39 100644 --- a/source/core/src/main/com/csse3200/game/entities/configs/WeaponTowerConfig.java +++ b/source/core/src/main/com/csse3200/game/entities/configs/WeaponTowerConfig.java @@ -4,8 +4,40 @@ * Defines a basic set of properties stored in entities config files to be loaded by Entity Factories. */ public class WeaponTowerConfig { - public int health = 1; - public int baseAttack = 0; - public int cost = 1; - public float attackRate = 1; + private int health = 1; + private int baseAttack = 0; + private int cost = 1; + private float attackRate = 1; + + /** + * Function for getting tower's health + * @return The health of this tower + */ + public int getHealth() { + return this.health; + } + + /** + * Function for getting tower's base attack + * @return The base attach of this tower + */ + public int getBaseAttack() { + return this.baseAttack; + } + + /** + * Function for getting tower's cost + * @return The cost of this tower + */ + public int getCost() { + return this.cost; + } + + /** + * Function for getting tower's attack rate + * @return The attack rate of this tower + */ + public float getAttackRate() { + return this.attackRate; + } } diff --git a/source/core/src/main/com/csse3200/game/entities/configs/baseTowerConfigs.java b/source/core/src/main/com/csse3200/game/entities/configs/baseTowerConfigs.java deleted file mode 100644 index c1b3f997a..000000000 --- a/source/core/src/main/com/csse3200/game/entities/configs/baseTowerConfigs.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.csse3200.game.entities.configs; - -/** - * Defines all tower configs to be loaded by the Tower Factory. - */ -public class baseTowerConfigs { - public WeaponTowerConfig weapon = new WeaponTowerConfig(); - public WallTowerConfig wall = new WallTowerConfig(); - public IncomeTowerConfig income = new IncomeTowerConfig(); - public FireTowerConfig fireTower = new FireTowerConfig(); - public StunTowerConfig stunTower = new StunTowerConfig(); - public TNTTowerConfigs TNTTower = new TNTTowerConfigs(); - public DroidTowerConfig DroidTower = new DroidTowerConfig(); - public FireworksTowerConfig fireworksTower = new FireworksTowerConfig(); - public PierceTowerConfig pierceTower = new PierceTowerConfig(); - public RicochetTowerConfig ricochetTower = new RicochetTowerConfig(); - public HealTowerConfig HealTower = new HealTowerConfig(); -} \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/entities/factories/BombshipFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/BombshipFactory.java index b96ad1e59..f2e9a50a1 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/BombshipFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/BombshipFactory.java @@ -11,7 +11,6 @@ import com.csse3200.game.entities.configs.*; import com.csse3200.game.files.FileLoader; import com.csse3200.game.physics.PhysicsLayer; -import com.csse3200.game.physics.PhysicsUtils; import com.csse3200.game.physics.components.ColliderComponent; import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.physics.components.PhysicsComponent; @@ -20,7 +19,6 @@ /** * Factory to create non-playable human character (NPC) entities with predefined components. - * * These may be modified to become controllable characters in future sprints. * *

Each NPC entity type should have a creation method that returns a corresponding entity. @@ -31,19 +29,16 @@ * similar characteristics. */ public class BombshipFactory { - private static final int COMBAT_TASK_PRIORITY = 2; private static final int BOMBSHIP_RANGE = 30; private static final BombshipConfigs configs = FileLoader.readClass(BombshipConfigs.class, "configs/Bombship.json"); - private static final float HUMAN_SCALE_X = 1f; private static final float HUMAN_SCALE_Y = 0.8f; /** * Creates an Engineer entity, based on a base Human entity, with the appropriate components and animations * - * * @return entity */ public static Entity createBombship() { @@ -75,17 +70,12 @@ public static Entity createBombship() { * @return entity */ public static Entity createBaseshipNPC() { - - - Entity ship = - new Entity() - .addComponent(new PhysicsComponent()) - .addComponent(new PhysicsMovementComponent()) - .addComponent(new ColliderComponent()) - .addComponent(new HitboxComponent().setLayer(PhysicsLayer.BOMBSHIP)) - .addComponent(new TouchAttackComponent(PhysicsLayer.NPC, 1.5f)); - - return ship; + return new Entity() + .addComponent(new PhysicsComponent()) + .addComponent(new PhysicsMovementComponent()) + .addComponent(new ColliderComponent()) + .addComponent(new HitboxComponent().setLayer(PhysicsLayer.BOMBSHIP)) + .addComponent(new TouchAttackComponent(PhysicsLayer.NPC, 1.5f)); } private BombshipFactory() { diff --git a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java index 43cce2dd8..9f5f3bac3 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java @@ -1,9 +1,7 @@ package com.csse3200.game.entities.factories; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.physics.box2d.Filter; import com.csse3200.game.components.EffectComponent; -import com.csse3200.game.components.EffectsComponent; import com.csse3200.game.components.tasks.DroidCombatTask; import com.csse3200.game.components.tasks.TNTTowerCombatTask; import com.csse3200.game.components.tasks.*; @@ -23,19 +21,21 @@ import com.csse3200.game.physics.components.PhysicsComponent; import com.csse3200.game.files.FileLoader; import com.csse3200.game.rendering.AnimationRenderComponent; -import com.csse3200.game.rendering.TextureRenderComponent; import com.csse3200.game.services.ServiceLocator; -import com.csse3200.game.input.UpgradeUIComponent;import java.util.HashSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.HashSet; import java.util.Set; - /** * Factory to create a tower entity. * * Predefined tower properties are loaded from a config stored as a json file and should have - * the properties stores in 'baseTowerConfigs'. + * the properties stores in 'BaseTowerConfigs'. */ public class TowerFactory { + private static final Logger logger = LoggerFactory.getLogger(TowerFactory.class); + // Define a set to keep track of occupied lanes private static final Set occupiedLanes = new HashSet<>(); private static final int COMBAT_TASK_PRIORITY = 2; @@ -43,8 +43,6 @@ public class TowerFactory { private static final int TNT_TOWER_MAX_RANGE = 6; private static final int TNT_TOWER_RANGE = 6; private static final int TNT_KNOCK_BACK_FORCE = 10; - private static final String WALL_IMAGE = "images/towers/wall_tower.png"; - private static final String RESOURCE_TOWER = "images/towers/mine_tower.png"; private static final String TURRET_ATLAS = "images/towers/turret01.atlas"; private static final String FIRE_TOWER_ATLAS = "images/towers/fire_tower_atlas.atlas"; private static final String STUN_TOWER_ATLAS = "images/towers/stun_tower.atlas"; @@ -105,29 +103,29 @@ public class TowerFactory { private static final float RICOCHET_TOWER_ANIM_ATTACK_SPEED = 0.12f; private static final String PIERCE_TOWER_ALERT_ANIM ="Warning"; private static final float PIERCE_TOWER_ANIM_ATTACK_SPEED = 0.12f; - private static final int INCOME_INTERVAL = 300; + // private static final int INCOME_INTERVAL = 300; private static final int INCOME_TASK_PRIORITY = 1; private static final String ECO_ATLAS = "images/economy/econ-tower.atlas"; private static final String ECO_MOVE = "move1"; private static final String ECO_IDLE = "idle"; private static final float ECO_IDLE_SPEED = 0.3f; - private static final baseTowerConfigs configs = - FileLoader.readClass(baseTowerConfigs.class, "configs/tower.json"); + private static final BaseTowerConfigs configs = + FileLoader.readClass(BaseTowerConfigs.class, "configs/tower.json"); + /** * Creates an income tower that generates scrap * @return income */ public static Entity createIncomeTower() { Entity income = createBaseTower(); - IncomeTowerConfig config = configs.income; + IncomeTowerConfig config = configs.getIncome(); // Create the CurrencyIncomeTask and add it to the AITaskComponent - CurrencyTask currencyTask = new CurrencyTask(INCOME_TASK_PRIORITY, (int) config.incomeRate); + CurrencyTask currencyTask = new CurrencyTask(INCOME_TASK_PRIORITY, (int) config.getIncomeRate()); AITaskComponent aiTaskComponent = new AITaskComponent().addTask(currencyTask); - // Contains all the animations that the tower will have AnimationRenderComponent animator = new AnimationRenderComponent( @@ -137,10 +135,10 @@ public static Entity createIncomeTower() { animator.addAnimation(ECO_MOVE, ECO_IDLE_SPEED, Animation.PlayMode.NORMAL); income - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent(new CostComponent(config.cost)) - .addComponent(new IncomeUpgradeComponent(config.incomeRate)) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) + .addComponent(new IncomeUpgradeComponent(config.getIncomeRate())) .addComponent(aiTaskComponent) .addComponent(animator) .addComponent(new EconTowerAnimationController()); @@ -148,9 +146,13 @@ public static Entity createIncomeTower() { return income; } + /** + * Create wall tower + * @return entity + */ public static Entity createWallTower() { Entity wall = createBaseTower(); - WallTowerConfig config = configs.wall; + WallTowerConfig config = configs.getWall(); AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new WallTowerDestructionTask(COMBAT_TASK_PRIORITY,TNT_TOWER_MAX_RANGE)); @@ -164,9 +166,9 @@ public static Entity createWallTower() { wall .addComponent(aiTaskComponent) - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent(new CostComponent(config.cost)) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) .addComponent(animator) .addComponent(new WallTowerAnimationController()); @@ -175,7 +177,6 @@ public static Entity createWallTower() { return wall; } - /** * Create a type of TNT that explodes once it detects a mob within a certain range. * Upon detonation, the TNT will apply both knock-back and health damage to the affected mobs @@ -187,7 +188,7 @@ public static Entity createTNTTower() { .setLayer(PhysicsLayer.NONE) .setSensor(true); TNTTower.getComponent(ColliderComponent.class).setSensor(true); - TNTTowerConfigs config = configs.TNTTower; + TNTTowerConfigs config = configs.getTNTTower(); AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new TNTTowerCombatTask(COMBAT_TASK_PRIORITY,TNT_TOWER_MAX_RANGE)); @@ -202,8 +203,9 @@ public static Entity createTNTTower() { animator.addAnimation(EXPLODE_ANIM,EXPLODE_SPEED, Animation.PlayMode.NORMAL); TNTTower - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new CostComponent(config.cost)) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) .addComponent(new TNTDamageComponent(PhysicsLayer.NPC,TNT_KNOCK_BACK_FORCE,TNT_TOWER_RANGE)) .addComponent(aiTaskComponent) .addComponent(animator) @@ -222,8 +224,8 @@ public static Entity createTNTTower() { * @return entity */ public static Entity createDroidTower() { - Entity DroidTower = createBaseTower(); - DroidTowerConfig config = configs.DroidTower; + Entity droidTower = createBaseTower(); + DroidTowerConfig config = configs.getDroidTower(); AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new DroidCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE)); @@ -241,17 +243,15 @@ public static Entity createDroidTower() { animator.addAnimation(GO_UP,DROID_SPEED, Animation.PlayMode.NORMAL); animator.addAnimation(GO_DOWN,DROID_SPEED, Animation.PlayMode.NORMAL); - - - DroidTower - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent(new CostComponent(config.cost)) + droidTower + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) .addComponent(new DroidAnimationController()) .addComponent(animator) .addComponent(aiTaskComponent); - return DroidTower; + return droidTower; } @@ -262,7 +262,7 @@ public static Entity createDroidTower() { */ public static Entity createWeaponTower() { Entity weapon = createBaseTower(); - WeaponTowerConfig config = configs.weapon; + WeaponTowerConfig config = configs.getWeapon(); // AiTaskComponent will run the tower task which carries out detection of targets and trigger events AITaskComponent aiTaskComponent = new AITaskComponent() @@ -279,15 +279,14 @@ public static Entity createWeaponTower() { animator.addAnimation(FIRE_ANIM, (2*FIRE_SPEED), Animation.PlayMode.LOOP); weapon - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent(new CostComponent(config.cost)) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) .addComponent(aiTaskComponent) .addComponent(animator) .addComponent(new TowerAnimationController()); return weapon; - } /** @@ -296,7 +295,7 @@ public static Entity createWeaponTower() { */ public static Entity createFireTower() { Entity fireTower = createBaseTower(); - FireTowerConfig config = configs.fireTower; + FireTowerConfig config = configs.getFireTower(); //Component that handles triggering events and animations AITaskComponent aiTaskComponent = new AITaskComponent() @@ -312,12 +311,13 @@ public static Entity createFireTower() { animator.addAnimation(FIRE_TOWER_DEATH_ANIM, FIRE_TOWER_DEATH_SPEED, Animation.PlayMode.NORMAL); fireTower - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent(new CostComponent(config.cost)) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) .addComponent(aiTaskComponent) .addComponent(animator) .addComponent(new FireTowerAnimationController()); + fireTower.setScale(1.25f, 1.25f); return fireTower; } @@ -328,7 +328,7 @@ public static Entity createFireTower() { */ public static Entity createStunTower() { Entity stunTower = createBaseTower(); - StunTowerConfig config = configs.stunTower; + StunTowerConfig config = configs.getStunTower(); AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new StunTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE)); @@ -338,13 +338,13 @@ public static Entity createStunTower() { ServiceLocator.getResourceService() .getAsset(STUN_TOWER_ATLAS, TextureAtlas.class)); animator.addAnimation(STUN_TOWER_IDLE_ANIM, STUN_TOWER_IDLE_SPEED, Animation.PlayMode.LOOP); - animator.addAnimation(STUN_TOWER_ATTACK_ANIM, ((STUN_TOWER_ATTACK_SPEED+ 0.20f)), Animation.PlayMode.LOOP); + animator.addAnimation(STUN_TOWER_ATTACK_ANIM, (STUN_TOWER_ATTACK_SPEED+ 0.20f), Animation.PlayMode.LOOP); animator.addAnimation(STUN_TOWER_DEATH_ANIM, STUN_TOWER_DEATH_SPEED, Animation.PlayMode.NORMAL); stunTower - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent((new CostComponent(config.cost))) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) .addComponent(aiTaskComponent) .addComponent(animator) .addComponent(new StunTowerAnimationController()); @@ -359,12 +359,11 @@ public static Entity createStunTower() { */ public static Entity createFireworksTower() { Entity fireworksTower = createBaseTower(); - FireworksTowerConfig config = configs.fireworksTower; + FireworksTowerConfig config = configs.getFireworksTower(); AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new FireworksTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE)); - AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService() @@ -374,9 +373,9 @@ public static Entity createFireworksTower() { animator.addAnimation(FIREWORKS_TOWER_DEATH_ANIM, FIREWORKS_TOWER_ANIM_SPEED, Animation.PlayMode.NORMAL); fireworksTower - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent((new CostComponent(config.cost))) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) + .addComponent(new CostComponent(config.getCost())) .addComponent(aiTaskComponent) .addComponent(animator) .addComponent(new FireworksTowerAnimationController()); @@ -390,7 +389,7 @@ public static Entity createFireworksTower() { */ public static Entity createPierceTower() { Entity pierceTower = createBaseTower(); - PierceTowerConfig config = configs.pierceTower; + PierceTowerConfig config = configs.getPierceTower(); AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new PierceTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE)); @@ -404,13 +403,12 @@ public static Entity createPierceTower() { animator.addAnimation(PIERCE_TOWER_DEATH_ANIM, PIERCE_TOWER_ANIM_ATTACK_SPEED, Animation.PlayMode.NORMAL); animator.addAnimation(PIERCE_TOWER_ALERT_ANIM, PIERCE_TOWER_ANIM_ATTACK_SPEED, Animation.PlayMode.NORMAL); - pierceTower .addComponent(animator) .addComponent(new PierceTowerAnimationController()) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent((new CostComponent(config.cost))) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new CostComponent(config.getCost())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) .addComponent(aiTaskComponent); pierceTower.setScale(1.5f, 1.5f); @@ -423,7 +421,7 @@ public static Entity createPierceTower() { */ public static Entity createRicochetTower() { Entity ricochetTower = createBaseTower(); - RicochetTowerConfig config = configs.ricochetTower; + RicochetTowerConfig config = configs.getRicochetTower(); AITaskComponent aiTaskComponent = new AITaskComponent() .addTask(new RicochetTowerCombatTask(COMBAT_TASK_PRIORITY, WEAPON_TOWER_MAX_RANGE)); @@ -433,12 +431,13 @@ public static Entity createRicochetTower() { animator.addAnimation(RICOCHET_TOWER_ATTACK_ANIM,(2*RICOCHET_TOWER_ANIM_ATTACK_SPEED),Animation.PlayMode.LOOP); animator.addAnimation(RICOCHET_TOWER_DEATH_ANIM,RICOCHET_TOWER_ANIM_ATTACK_SPEED,Animation.PlayMode.NORMAL); animator.addAnimation(RICOCHET_TOWER_IDLE_ANIM,RICOCHET_TOWER_ANIM_ATTACK_SPEED,Animation.PlayMode.LOOP); + ricochetTower .addComponent(animator) .addComponent(new RicochetTowerAnimationController()) - .addComponent(new UpgradableStatsComponent(config.attackRate)) - .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) - .addComponent((new CostComponent(config.cost))) + .addComponent(new CombatStatsComponent(config.getHealth(), config.getBaseAttack())) + .addComponent(new CostComponent(config.getCost())) + .addComponent(new UpgradableStatsComponent(config.getAttackRate())) .addComponent(aiTaskComponent); // ADD ANIMATION COMPONENTS @@ -453,7 +452,6 @@ public static Entity createRicochetTower() { public static Entity createBaseTower() { // we're going to add more components later on - Entity tower = new Entity() .addComponent(new ColliderComponent()) .addComponent(new EffectComponent(false)) @@ -468,9 +466,10 @@ public static Entity createBaseTower() { tower.getComponent(ColliderComponent.class).setAsBoxAligned(new Vector2(1f, 1f), PhysicsComponent.AlignX.CENTER, PhysicsComponent.AlignY.CENTER); return tower; } + public static Entity createAndPlaceTower(int lane) { if (isLaneOccupied(lane)) { - System.out.println("Lane " + lane + " is already occupied by a tower"); + logger.info(String.format("Lane %d is already occupied by a tower", lane)); return null; } diff --git a/source/core/src/test/com/csse3200/game/components/tasks/DroidCombatTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/DroidCombatTaskTest.java index d31f3505d..b4a1c7be7 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/DroidCombatTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/DroidCombatTaskTest.java @@ -22,7 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class DroidCombatTaskTest { +class DroidCombatTaskTest { DroidCombatTask droidCombatTask; @BeforeEach @@ -35,7 +35,7 @@ void setUp() { } @Test - public void testStartTriggersWalkEvent() { + void testStartTriggersWalkEvent() { Entity entity = createDroid(); EventListener0 walkListener = mock(EventListener0.class); // Deploy Droid in the walking state @@ -45,7 +45,7 @@ public void testStartTriggersWalkEvent() { } @Test - public void testUpdateTowerStateWithTargetInRange() { + void testUpdateTowerStateWithTargetInRange() { Entity entity = createDroid(); entity.setPosition(10,10); @@ -98,7 +98,7 @@ public void testUpdateTowerStateWithTargetInRange() { } @Test - public void testUpdateTowerStateWithTargetNotInRange() { + void testUpdateTowerStateWithTargetNotInRange() { Entity entity = createDroid(); entity.setPosition(10, 10); @@ -124,7 +124,6 @@ public void testUpdateTowerStateWithTargetNotInRange() { assertEquals(DroidCombatTask.STATE.IDLE, droidCombatTask.getState()); } - Entity createDroid() { AITaskComponent aiTaskComponent = new AITaskComponent().addTask(droidCombatTask); Entity entity = new Entity().addComponent(aiTaskComponent) diff --git a/source/core/src/test/com/csse3200/game/components/tasks/FireTowerCombatTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/FireTowerCombatTaskTest.java index ec0cbe0ef..83dffd6ee 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/FireTowerCombatTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/FireTowerCombatTaskTest.java @@ -22,7 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class FireTowerCombatTaskTest { +class FireTowerCombatTaskTest { FireTowerCombatTask fireTowerCombatTask; @BeforeEach @@ -39,7 +39,7 @@ void setUp() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testStartTriggersIdleEvent() { + void testStartTriggersIdleEvent() { Entity entity = createFireTower(); EventListener0 idleListener = mock(EventListener0.class); // Deploy Droid in the walking state @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetInRange() { + void testUpdateTowerStateWithTargetInRange() { Entity entity = createFireTower(); entity.setPosition(10, 10); @@ -91,7 +91,7 @@ public void testUpdateTowerStateWithTargetInRange() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetNotInRange() { + void testUpdateTowerStateWithTargetNotInRange() { Entity entity = createFireTower(); entity.setPosition(10, 10); diff --git a/source/core/src/test/com/csse3200/game/components/tasks/FireworksTowerCombatTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/FireworksTowerCombatTaskTest.java index e7addd508..53b6adc57 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/FireworksTowerCombatTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/FireworksTowerCombatTaskTest.java @@ -22,7 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class FireworksTowerCombatTaskTest { +class FireworksTowerCombatTaskTest { FireworksTowerCombatTask fireworksTowerCombatTask; @BeforeEach @@ -39,7 +39,7 @@ void setUp() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testStartTriggersIdleEvent() { + void testStartTriggersIdleEvent() { Entity entity = createFireworksTower(); EventListener0 idleListener = mock(EventListener0.class); // Deploy Droid in the walking state @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetInRange() { + void testUpdateTowerStateWithTargetInRange() { Entity entity = createFireworksTower(); entity.setPosition(10, 10); @@ -80,7 +80,7 @@ public void testUpdateTowerStateWithTargetInRange() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetNotInRange() { + void testUpdateTowerStateWithTargetNotInRange() { Entity entity = createFireworksTower(); entity.setPosition(10, 10); diff --git a/source/core/src/test/com/csse3200/game/components/tasks/PierceTowerCombatTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/PierceTowerCombatTaskTest.java index f8d060992..81041aa3a 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/PierceTowerCombatTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/PierceTowerCombatTaskTest.java @@ -22,7 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class PierceTowerCombatTaskTest { +class PierceTowerCombatTaskTest { PierceTowerCombatTask pierceTowerCombatTask; @BeforeEach @@ -39,7 +39,7 @@ void setUp() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testStartTriggersIdleEvent() { + void testStartTriggersIdleEvent() { Entity entity = createPierceTower(); EventListener0 idleListener = mock(EventListener0.class); // Deploy Droid in the walking state @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetInRange() { + void testUpdateTowerStateWithTargetInRange() { Entity entity = createPierceTower(); entity.setPosition(10, 10); @@ -81,7 +81,7 @@ public void testUpdateTowerStateWithTargetInRange() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetNotInRange() { + void testUpdateTowerStateWithTargetNotInRange() { Entity entity = createPierceTower(); entity.setPosition(10, 10); diff --git a/source/core/src/test/com/csse3200/game/components/tasks/RicochetTowerCombatTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/RicochetTowerCombatTaskTest.java index e64d534cf..580e5cff2 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/RicochetTowerCombatTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/RicochetTowerCombatTaskTest.java @@ -22,7 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class RicochetTowerCombatTaskTest { +class RicochetTowerCombatTaskTest { RicochetTowerCombatTask ricochetTowerCombatTask; @BeforeEach @@ -39,7 +39,7 @@ void setUp() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testStartTriggersIdleEvent() { + void testStartTriggersIdleEvent() { Entity entity = createRicochetTower(); EventListener0 idleListener = mock(EventListener0.class); // Deploy Droid in the walking state @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetInRange() { + void testUpdateTowerStateWithTargetInRange() { Entity entity = createRicochetTower(); entity.setPosition(10, 10); @@ -80,7 +80,7 @@ public void testUpdateTowerStateWithTargetInRange() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetNotInRange() { + void testUpdateTowerStateWithTargetNotInRange() { Entity entity = createRicochetTower(); entity.setPosition(10, 10); diff --git a/source/core/src/test/com/csse3200/game/components/tasks/StunTowerCombatTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/StunTowerCombatTaskTest.java index 30f490340..c589205ef 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/StunTowerCombatTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/StunTowerCombatTaskTest.java @@ -22,7 +22,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class StunTowerCombatTaskTest { +class StunTowerCombatTaskTest { StunTowerCombatTask stunTowerCombatTask; @BeforeEach @@ -39,7 +39,7 @@ void setUp() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testStartTriggersIdleEvent() { + void testStartTriggersIdleEvent() { Entity entity = createStunTower(); EventListener0 idleListener = mock(EventListener0.class); // Deploy Droid in the walking state @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() { * in DroidCombatTaskTest by Mohamad Dabboussi */ @Test - public void testUpdateTowerStateWithTargetInRange() { + void testUpdateTowerStateWithTargetInRange() { Entity entity = createStunTower(); entity.setPosition(10, 10); diff --git a/source/core/src/test/com/csse3200/game/components/tasks/TNTTowerCombatTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/TNTTowerCombatTaskTest.java index 74ff509f7..5781351a9 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/TNTTowerCombatTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/TNTTowerCombatTaskTest.java @@ -19,7 +19,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class TNTTowerCombatTaskTest { +class TNTTowerCombatTaskTest { TNTTowerCombatTask tntTowerCombatTask; @BeforeEach @@ -34,7 +34,7 @@ void setUp() { } @Test - public void testStartTriggersDefaultEvent() { + void testStartTriggersDefaultEvent() { Entity entity = createTNT(); EventListener0 defaultStartListener = mock(EventListener0.class); @@ -46,7 +46,7 @@ public void testStartTriggersDefaultEvent() { } @Test - public void testUpdateTowerStateWithTargetInRange() { + void testUpdateTowerStateWithTargetInRange() { Entity entity = createTNT(); entity.setPosition(10,10); @@ -89,7 +89,7 @@ public void testUpdateTowerStateWithTargetInRange() { } @Test - public void testStayAtIdleWhenNoTargetInRange() { + void testStayAtIdleWhenNoTargetInRange() { Entity entity = createTNT(); entity.setPosition(10,10); diff --git a/source/core/src/test/com/csse3200/game/components/tower/DroidAnimationControllerTest.java b/source/core/src/test/com/csse3200/game/components/tower/DroidAnimationControllerTest.java index a752a20c0..201334d3f 100644 --- a/source/core/src/test/com/csse3200/game/components/tower/DroidAnimationControllerTest.java +++ b/source/core/src/test/com/csse3200/game/components/tower/DroidAnimationControllerTest.java @@ -17,8 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(GameExtension.class) -public class DroidAnimationControllerTest { - +class DroidAnimationControllerTest { private Entity mockEntity; private final String[] texture = {"images/towers/DroidTower.png"}; private final String[] atlas = {"images/towers/DroidTower.atlas"}; @@ -28,7 +27,7 @@ public class DroidAnimationControllerTest { }; @BeforeEach - public void setUp() { + void setUp() { ServiceLocator.registerPhysicsService(new PhysicsService()); RenderService render = new RenderService(); render.setDebug(mock(DebugRenderer.class)); @@ -45,43 +44,43 @@ public void setUp() { } @Test - public void testAnimateWalk() { + void testAnimateWalk() { mockEntity.getEvents().trigger("walkStart"); assertEquals("walk", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateDefault() { + void testAnimateDefault() { mockEntity.getEvents().trigger("idleStart"); assertEquals("idle", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateGoUp() { + void testAnimateGoUp() { mockEntity.getEvents().trigger("goUpStart"); assertEquals("goUp", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateGoDown() { + void testAnimateGoDown() { mockEntity.getEvents().trigger("goDownStart"); assertEquals("goDown", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateAttackUp() { + void testAnimateAttackUp() { mockEntity.getEvents().trigger("attackUpStart"); assertEquals("attackUp", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateAttackDown() { + void testAnimateAttackDown() { mockEntity.getEvents().trigger("attackDownStart"); assertEquals("attackDown", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateDeath() { + void testAnimateDeath() { mockEntity.getEvents().trigger("deathStart"); assertEquals("death", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } diff --git a/source/core/src/test/com/csse3200/game/components/tower/FireTowerAnimationControllerTest.java b/source/core/src/test/com/csse3200/game/components/tower/FireTowerAnimationControllerTest.java index c8187529b..36e149af4 100644 --- a/source/core/src/test/com/csse3200/game/components/tower/FireTowerAnimationControllerTest.java +++ b/source/core/src/test/com/csse3200/game/components/tower/FireTowerAnimationControllerTest.java @@ -17,8 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(GameExtension.class) -public class FireTowerAnimationControllerTest { - +class FireTowerAnimationControllerTest { private Entity mockEntity; private final String[] texture = {"images/towers/fire_tower_atlas.png"}; private final String[] atlas = {"images/towers/fire_tower_atlas.atlas"}; @@ -28,7 +27,7 @@ public class FireTowerAnimationControllerTest { }; @BeforeEach - public void setUp() { + void setUp() { ServiceLocator.registerPhysicsService(new PhysicsService()); RenderService render = new RenderService(); render.setDebug(mock(DebugRenderer.class)); @@ -45,25 +44,25 @@ public void setUp() { } @Test - public void testAnimateWalk() { + void testAnimateWalk() { mockEntity.getEvents().trigger("startIdle"); assertEquals("idle", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateDefault() { + void testAnimateDefault() { mockEntity.getEvents().trigger("startAttackPrep"); assertEquals("prepAttack", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateGoUp() { + void testAnimateGoUp() { mockEntity.getEvents().trigger("startAttack"); assertEquals("attack", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateDeath() { + void testAnimateDeath() { mockEntity.getEvents().trigger("startDeath"); assertEquals("death", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } diff --git a/source/core/src/test/com/csse3200/game/components/tower/StunTowerAnimationControllerTest.java b/source/core/src/test/com/csse3200/game/components/tower/StunTowerAnimationControllerTest.java index 7e5c272ba..00688d8b5 100644 --- a/source/core/src/test/com/csse3200/game/components/tower/StunTowerAnimationControllerTest.java +++ b/source/core/src/test/com/csse3200/game/components/tower/StunTowerAnimationControllerTest.java @@ -17,8 +17,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(GameExtension.class) -public class StunTowerAnimationControllerTest { - +class StunTowerAnimationControllerTest { private Entity mockEntity; private final String[] texture = {"images/towers/stun_tower.png"}; private final String[] atlas = {"images/towers/stun_tower.atlas"}; @@ -27,7 +26,7 @@ public class StunTowerAnimationControllerTest { }; @BeforeEach - public void setUp() { + void setUp() { ServiceLocator.registerPhysicsService(new PhysicsService()); RenderService render = new RenderService(); render.setDebug(mock(DebugRenderer.class)); @@ -44,19 +43,19 @@ public void setUp() { } @Test - public void testAnimateWalk() { + void testAnimateWalk() { mockEntity.getEvents().trigger("startIdle"); assertEquals("idle", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateDefault() { + void testAnimateDefault() { mockEntity.getEvents().trigger("startAttack"); assertEquals("attack", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } @Test - public void testAnimateGoUp() { + void testAnimateGoUp() { mockEntity.getEvents().trigger("startDeath"); assertEquals("death", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation()); } diff --git a/source/core/src/test/com/csse3200/game/components/tower/TNTAnimationControllerTest.java b/source/core/src/test/com/csse3200/game/components/tower/TNTAnimationControllerTest.java index a76f4ad18..3a755c061 100644 --- a/source/core/src/test/com/csse3200/game/components/tower/TNTAnimationControllerTest.java +++ b/source/core/src/test/com/csse3200/game/components/tower/TNTAnimationControllerTest.java @@ -16,11 +16,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - - @ExtendWith(GameExtension.class) -public class TNTAnimationControllerTest { - +class TNTAnimationControllerTest { private Entity mockEntity; private final String[] texture = {"images/towers/TNTTower.png"}; private final String[] atlas = {"images/towers/TNTTower.atlas"}; @@ -29,9 +26,8 @@ public class TNTAnimationControllerTest { "sounds/towers/explosion.mp3" }; - @BeforeEach - public void setUp() { + void setUp() { // Initialize the TNTAnimationController object ServiceLocator.registerPhysicsService(new PhysicsService()); RenderService render = new RenderService(); @@ -49,7 +45,7 @@ public void setUp() { } @Test - public void testAnimateDig() { + void testAnimateDig() { // Trigger the animateDig method mockEntity.getEvents().trigger("digStart"); @@ -59,7 +55,7 @@ public void testAnimateDig() { } @Test - public void testAnimateDefault() { + void testAnimateDefault() { // Trigger the animateDefault method mockEntity.getEvents().trigger("defaultStart"); @@ -68,7 +64,7 @@ public void testAnimateDefault() { } @Test - public void testAnimateExplode() { + void testAnimateExplode() { // Trigger the animateExplode method mockEntity.getEvents().trigger("explodeStart"); diff --git a/source/core/src/test/com/csse3200/game/components/tower/TNTDamageComponentTest.java b/source/core/src/test/com/csse3200/game/components/tower/TNTDamageComponentTest.java index 1b8f988aa..d6263163c 100644 --- a/source/core/src/test/com/csse3200/game/components/tower/TNTDamageComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/tower/TNTDamageComponentTest.java @@ -20,8 +20,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(GameExtension.class) -public class TNTDamageComponentTest { - +class TNTDamageComponentTest { private GameTime gameTime; private Entity Attacker; private Entity Target_1; @@ -31,7 +30,7 @@ public class TNTDamageComponentTest { private final String[] atlas = {"images/towers/TNTTower.atlas"}; @BeforeEach - public void setUp() { + void setUp() { gameTime = mock(GameTime.class); when(gameTime.getDeltaTime()).thenReturn(1f); ServiceLocator.registerTimeSource(gameTime); @@ -53,29 +52,24 @@ public void setUp() { ServiceLocator.getEntityService().register(Target_1); ServiceLocator.getEntityService().register(Target_2); ServiceLocator.getEntityService().register(Entity_3); - - } @Test - public void TestTNTDamageOnTargetsThatAreInRange() { + void TestTNTDamageOnTargetsThatAreInRange() { Attacker.setPosition(10,10); Target_1.setPosition(12,10);// Same lane and inside radius Attacker.getEvents().trigger("TNTDamageStart"); assertEquals(80, Target_1.getComponent(CombatStatsComponent.class).getHealth()); - - } @Test - public void TestTNTDamageOnTargetsThatAreNoTInRange() { + void TestTNTDamageOnTargetsThatAreNoTInRange() { Attacker.setPosition(10,10); Target_1.setPosition(15,10); // on the same lane but outside the radius Target_2.setPosition(11,12); // inside the radius but outside the lane - Attacker.getEvents().trigger("TNTDamageStart"); //Nothing should happen assertEquals(100, Target_2.getComponent(CombatStatsComponent.class).getHealth()); @@ -83,11 +77,10 @@ public void TestTNTDamageOnTargetsThatAreNoTInRange() { } @Test - public void TestTNTDamageOnEntitiesThatAreNotTargets() { + void TestTNTDamageOnEntitiesThatAreNotTargets() { Attacker.setPosition(10,10); Entity_3.setPosition(12,10); // on the same lane and inside the radius but different target layer - Attacker.getEvents().trigger("TNTDamageStart"); //Nothing should happen assertEquals(100, Entity_3.getComponent(CombatStatsComponent.class).getHealth()); diff --git a/source/core/src/test/com/csse3200/game/entities/factories/TowerFactoryTest.java b/source/core/src/test/com/csse3200/game/entities/factories/TowerFactoryTest.java index 01462c0f1..65a7709ee 100644 --- a/source/core/src/test/com/csse3200/game/entities/factories/TowerFactoryTest.java +++ b/source/core/src/test/com/csse3200/game/entities/factories/TowerFactoryTest.java @@ -26,8 +26,7 @@ import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(GameExtension.class) -public class TowerFactoryTest { - +class TowerFactoryTest { private Entity baseTower; private Entity weaponTower; private Entity wallTower; @@ -91,8 +90,7 @@ public void setUp() { } @Test - public void testCreateBaseTowerNotNull() { - + void testCreateBaseTowerNotNull() { assertNotNull(baseTower, "Base tower should not be null"); assertNotNull(weaponTower, "Weaponry tower should not be null"); assertNotNull(wallTower, "Wall tower should not be null"); @@ -103,7 +101,7 @@ public void testCreateBaseTowerNotNull() { } @Test - public void testCreateBaseTowerHasColliderComponent() { + void testCreateBaseTowerHasColliderComponent() { assertNotNull(baseTower.getComponent(ColliderComponent.class), "Base tower should have ColliderComponent"); assertNotNull(weaponTower.getComponent(ColliderComponent.class), @@ -121,7 +119,7 @@ public void testCreateBaseTowerHasColliderComponent() { } @Test - public void testCreateBaseTowerHasHitboxComponent() { + void testCreateBaseTowerHasHitboxComponent() { assertNotNull(baseTower.getComponent(HitboxComponent.class), "Base tower should have HitboxComponent"); assertNotNull(weaponTower.getComponent(HitboxComponent.class), @@ -139,7 +137,7 @@ public void testCreateBaseTowerHasHitboxComponent() { } @Test - public void testCreateBaseTowerHasPhysicsComponent() { + void testCreateBaseTowerHasPhysicsComponent() { assertNotNull(baseTower.getComponent(PhysicsComponent.class), "Base tower should have PhysicsComponent"); assertNotNull(weaponTower.getComponent(PhysicsComponent.class), @@ -157,7 +155,7 @@ public void testCreateBaseTowerHasPhysicsComponent() { } @Test - public void testCreateBaseTowerPhysicsComponentStaticBody() { + void testCreateBaseTowerPhysicsComponentStaticBody() { PhysicsComponent physicsComponent = baseTower.getComponent(PhysicsComponent.class); PhysicsComponent physicsComponent1 = weaponTower.getComponent(PhysicsComponent.class); PhysicsComponent physicsComponent2 = wallTower.getComponent(PhysicsComponent.class); @@ -166,18 +164,24 @@ public void testCreateBaseTowerPhysicsComponentStaticBody() { PhysicsComponent physicsComponent5 = tntTower.getComponent(PhysicsComponent.class); PhysicsComponent physicsComponent6 = droidTower.getComponent(PhysicsComponent.class); - assertSame(physicsComponent.getBody().getType(), BodyType.StaticBody, "PhysicsComponent should be of type StaticBody"); - assertSame(physicsComponent1.getBody().getType(), BodyType.StaticBody, "PhysicsComponent1 should be of type StaticBody"); - assertSame(physicsComponent2.getBody().getType(), BodyType.StaticBody, "PhysicsComponent2 should be of type StaticBody"); - assertSame(physicsComponent3.getBody().getType(), BodyType.StaticBody, "StunTower's PhysicsComponent should be of type StaticBody"); - assertSame(physicsComponent4.getBody().getType(), BodyType.StaticBody, "FireTower's PhysicsComponent should be of type StaticBody"); - assertSame(physicsComponent5.getBody().getType(), BodyType.StaticBody, "TNT tower's PhysicsComponent should be of type StaticBody"); - assertSame(physicsComponent6.getBody().getType(), BodyType.StaticBody, "Droid Tower's PhysicsComponent should be of type StaticBody"); + assertSame(BodyType.StaticBody, physicsComponent.getBody().getType(), + "PhysicsComponent should be of type StaticBody"); + assertSame(BodyType.StaticBody, physicsComponent1.getBody().getType(), + "PhysicsComponent1 should be of type StaticBody"); + assertSame(BodyType.StaticBody, physicsComponent2.getBody().getType(), + "PhysicsComponent2 should be of type StaticBody"); + assertSame(BodyType.StaticBody, physicsComponent3.getBody().getType(), + "StunTower's PhysicsComponent should be of type StaticBody"); + assertSame(BodyType.StaticBody, physicsComponent4.getBody().getType(), + "FireTower's PhysicsComponent should be of type StaticBody"); + assertSame(BodyType.StaticBody, physicsComponent5.getBody().getType(), + "TNT tower's PhysicsComponent should be of type StaticBody"); + assertSame(BodyType.StaticBody, physicsComponent6.getBody().getType(), + "Droid Tower's PhysicsComponent should be of type StaticBody"); } @Test - public void testWeaponTowerCombatStatsComponentAndCostComponent() { - + void testWeaponTowerCombatStatsComponentAndCostComponent() { assertEquals(75, weaponTower.getComponent(CombatStatsComponent.class).getHealth(), "Health should be 75"); assertEquals(15, weaponTower.getComponent(CombatStatsComponent.class).getBaseAttack(), @@ -211,14 +215,14 @@ public void testWeaponTowerCombatStatsComponentAndCostComponent() { } @Test - public void testWallTowerCombatStatsComponentAndCostComponent() { + void testWallTowerCombatStatsComponentAndCostComponent() { assertEquals(300, wallTower.getComponent(CombatStatsComponent.class).getHealth(), "Health should be 300"); assertEquals(0, wallTower.getComponent(CombatStatsComponent.class).getBaseAttack(), "BaseAttack should be 0"); assertEquals(45, wallTower.getComponent(CostComponent.class).getCost(), "Cost should be 45"); } @Test - public void weaponTowerHasAnimationComponent() { + void weaponTowerHasAnimationComponent() { assertNotNull(weaponTower.getComponent(AnimationRenderComponent.class)); assertNotNull(stunTower.getComponent(AnimationRenderComponent.class)); assertNotNull(fireTower.getComponent(AnimationRenderComponent.class)); @@ -227,7 +231,7 @@ public void weaponTowerHasAnimationComponent() { } @Test - public void testAttackerCollisionWithWall() { + void testAttackerCollisionWithWall() { Entity attacker = createAttacker(wallTower.getComponent(HitboxComponent.class).getLayer()); wallTower.setPosition(10f,10f); @@ -239,7 +243,6 @@ public void testAttackerCollisionWithWall() { ServiceLocator.getPhysicsService().getPhysics().update(); assertEquals(290, wallTower.getComponent(CombatStatsComponent.class).getHealth()); - } Entity createAttacker(short targetLayer) {