Skip to content

Commit

Permalink
Fix code smells DroidCombatTask (still remains 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhatminh451 committed Oct 11, 2023
1 parent 7d8efa9 commit 2e1107b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ public class DroidCombatTask extends DefaultTask implements PriorityTask {
public enum STATE {
IDLE, UP, DOWN, SHOOT_UP, SHOOT_DOWN, WALK, DIE
}
public STATE towerState = STATE.WALK;
private STATE towerState = STATE.WALK;

/**
* @param priority Task priority when targets are detected (0 when nothing detected). Must be a positive integer.
* @param maxRange Maximum effective range of the weapon tower. This determines the detection distance of targets
*/

public DroidCombatTask(int priority, float maxRange) {
this.priority = priority;
this.maxRange = maxRange;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void update() {
} else {
endTime = timeSource.getTime() + (INTERVAL * 1000);
}
}
}
}

/**
Expand Down Expand Up @@ -166,13 +167,6 @@ public void updateTowerState() {
}
}
}
/**
* For stopping the running task
*/
@Override
public void stop() {
super.stop();
}

/**
* Returns the current state of the tower.
Expand Down Expand Up @@ -214,4 +208,21 @@ public float getFireRateInterval() {
return fireRateInterval;
}

/**
* Function for getting the tower's state
*
* @return The tower's state
*/
public STATE getTowerState() {
return towerState;
}

/**
* Function setting the tower state
*
* @param newState New state needs to setted to the tower state
*/
public void setTowerState(STATE newState) {
this.towerState = newState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testUpdateTowerStateWithTargetInRange() {
entity.getEvents().addListener(DroidCombatTask.SHOOT_DOWN,shootDown);
//Jump to IDLE state
droidCombatTask.start();
droidCombatTask.towerState = DroidCombatTask.STATE.IDLE;
droidCombatTask.setTowerState(DroidCombatTask.STATE.IDLE);

ServiceLocator.getPhysicsService().getPhysics().update();
entity.update();
Expand Down Expand Up @@ -110,7 +110,7 @@ public void testUpdateTowerStateWithTargetNotInRange() {
entity.getEvents().addListener(DroidCombatTask.IDLE, idle);
entity.getEvents().addListener(DroidCombatTask.ATTACK_UP,attackUp);
//Jump to IDLE state
droidCombatTask.towerState = DroidCombatTask.STATE.IDLE;
droidCombatTask.setTowerState(DroidCombatTask.STATE.IDLE);

ServiceLocator.getPhysicsService().getPhysics().update();
entity.update();
Expand Down

0 comments on commit 2e1107b

Please sign in to comment.