Skip to content

Commit

Permalink
Fix 2 code smells in TNTTowerCombatTask (2 low)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhatminh451 committed Oct 16, 2023
1 parent da0102b commit 196dbb1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class TNTTowerCombatTask extends DefaultTask implements PriorityTask {
public static final String DEFAULT = "defaultStart";
public static final String DAMAGE = "TNTDamageStart";


// class attributes
private final int priority; // The active priority this task will have
private final float maxRange;
Expand All @@ -35,7 +34,7 @@ public class TNTTowerCombatTask extends DefaultTask implements PriorityTask {
private final GameTime timeSource;
private long endTime;
private final RaycastHit hit = new RaycastHit();
public boolean readToDelete = false;
private boolean readToDelete = false;

public enum STATE {
IDLE, EXPLODE, REMOVE
Expand All @@ -51,7 +50,6 @@ public TNTTowerCombatTask(int priority, float maxRange) {
this.maxRange = maxRange;
physics = ServiceLocator.getPhysicsService().getPhysics();
timeSource = ServiceLocator.getTimeSource();

}

/**
Expand Down Expand Up @@ -87,7 +85,6 @@ public void update() {
*/
public void updateTowerState() {
// configure tower state depending on target visibility

switch (towerState) {
case IDLE -> {
// targets detected in idle mode - start deployment
Expand All @@ -103,19 +100,10 @@ public void updateTowerState() {
owner.getEntity().getEvents().trigger(DAMAGE);
towerState = STATE.REMOVE;
}
case REMOVE -> {
default -> { // REMOVE
readToDelete = true;
}
}


}
/**
* For stopping the running task
*/
@Override
public void stop() {
super.stop();
}

/**
Expand All @@ -124,7 +112,6 @@ public void stop() {
*/
@Override
public int getPriority() {

if (isReadyToDelete()) {
owner.getEntity().setFlagForDelete(true);
return -1;
Expand Down Expand Up @@ -152,11 +139,8 @@ public boolean isTargetVisible() {
}

public boolean isReadyToDelete() {

return readToDelete;
}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

@ExtendWith(MockitoExtension.class)
public class TNTTowerCombatTaskTest {


TNTTowerCombatTask tntTowerCombatTask;

@BeforeEach
Expand All @@ -37,7 +35,6 @@ void setUp() {

@Test
public void testStartTriggersDefaultEvent() {

Entity entity = createTNT();

EventListener0 defaultStartListener = mock(EventListener0.class);
Expand All @@ -50,7 +47,6 @@ public void testStartTriggersDefaultEvent() {

@Test
public void testUpdateTowerStateWithTargetInRange() {

Entity entity = createTNT();
entity.setPosition(10,10);

Expand Down Expand Up @@ -90,12 +86,10 @@ public void testUpdateTowerStateWithTargetInRange() {
tntTowerCombatTask.updateTowerState();
// Set flag to dispose
assertTrue(tntTowerCombatTask.isReadyToDelete());

}

@Test
public void testStayAtIdleWhenNoTargetInRange() {

Entity entity = createTNT();
entity.setPosition(10,10);

Expand All @@ -117,7 +111,6 @@ public void testStayAtIdleWhenNoTargetInRange() {
verifyNoInteractions(defaultStartListener);
// still in idle
assertEquals(TNTTowerCombatTask.STATE.IDLE, tntTowerCombatTask.getState());

}

Entity createTNT() {
Expand All @@ -128,7 +121,6 @@ Entity createTNT() {
.addComponent(new ColliderComponent());
entity.create();
return entity;

}

Entity createNPC() {
Expand All @@ -139,6 +131,4 @@ Entity createNPC() {
Target.create();
return Target;
}


}

0 comments on commit 196dbb1

Please sign in to comment.