Skip to content

Commit

Permalink
Codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhendriks committed Aug 28, 2017
1 parent 9c2f02e commit fe9df6f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public abstract class AbstractBattleFieldMouseBehavior extends AbstractMouseBeha

protected Vector2D mouseCoordinates;

private Entity lastSelectedEntity;

private Cell hoverCell;

public AbstractBattleFieldMouseBehavior(BattleField battleField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* </p>
* <h2>State</h2>
* <p>
* An entity has state, usually a lifespan or somesort, therefor it is {@link Updateable}. The {@link #update(float)} method
* An entity has state, usually a lifespan or some sort, therefor it is {@link Updateable}. The {@link #update(float)} method
* is called by the {@link com.fundynamic.d2tm.game.state.PlayingState#update(GameContainer, StateBasedGame, int)} method.
* </p>
* <h2>Rendering:</h2>
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/fundynamic/d2tm/game/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public class Player implements Updateable {
private float credits;
private int animatedCredits;

private float creditsTimer = 0F;

public Player(String name, Recolorer.FactionColor factionColor) {
this(name, factionColor, 2000);
}
Expand Down Expand Up @@ -117,18 +115,6 @@ public int getAnimatedCredits() {

@Override
public void update(float deltaInSeconds) {
// float desiredCredits = Math.round(this.credits);
animatedCredits = (int) credits;
// if (animatedCredits != desiredCredits) {
// creditsTimer += deltaInSeconds;
// while (creditsTimer > 0.0F && animatedCredits != desiredCredits) {
// creditsTimer -= 0.01;
// if (animatedCredits < desiredCredits) {
// animatedCredits += 1;
// } else {
// animatedCredits -= 1;
// }
// }
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ private void moveToNextCellPixelByPixel(float deltaInSeconds) {
if (!vecToAdd.isZero()) {
unit.log("Arrived at cell");
unit.arrivedAtCell(coordinate.add(vecToAdd));
} else {
// unit.log("My offset is " + vecToAdd);
}

unit.setOffset(Vector2D.create(offsetX, offsetY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ public void render(Graphics graphics) {
}
}

public void drawLine(Entity from, Entity to) {

}

public void update(float delta) {
Vector2D translation = velocity.scale(delta);
viewingVector = viewingVectorPerimeter.makeSureVectorStaysWithin(viewingVector.add(translation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
public class IsWithinAnotherEntityTest extends AbstractD2TMTest{

@Test
public void WithinOther() {
public void withinOther() {
EntityData structure = new EntityData();
structure.type = EntityType.STRUCTURE;
structure.setWidth(64);
structure.setHeight(64);

EntityData unit = new EntityData();
structure.type = EntityType.UNIT;
structure.setWidth(32);
structure.setHeight(32);
unit.type = EntityType.UNIT;
unit.setWidth(32);
unit.setHeight(32);

Coordinate coordinate = Coordinate.create(32, 32);
TestableEntity refinery = new TestableEntity(coordinate, mock(SpriteSheet.class), structure, player, entityRepository).
setName("Refinery");

TestableEntity harvester = new TestableEntity(coordinate, mock(SpriteSheet.class), structure, player, entityRepository).
TestableEntity harvester = new TestableEntity(coordinate, mock(SpriteSheet.class), unit, player, entityRepository).
setName("Harvester");

harvester.enterOtherEntity(refinery);
Expand Down
38 changes: 18 additions & 20 deletions src/test/java/com/fundynamic/d2tm/game/entities/units/UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import com.fundynamic.d2tm.math.Coordinate;
import com.fundynamic.d2tm.math.MapCoordinate;
import com.fundynamic.d2tm.math.Vector2D;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.newdawn.slick.SlickException;

import java.util.List;
Expand Down Expand Up @@ -55,7 +53,7 @@ public void takingDamageReducesHitpoints() {
int damageInHitpoints = 5;
unit.takeDamage(damageInHitpoints, null);

Assert.assertEquals(hitPoints - damageInHitpoints, unit.getHitPoints());
assertEquals(hitPoints - damageInHitpoints, unit.getHitPoints());
}

// FLAKY TEST: Sometimes fails probably because 'random cell to move to' is the same as it was now...
Expand All @@ -66,7 +64,7 @@ public void cpuUnitMovesRandomlyAroundWhenTakingDamageFromUnknownEntity() {

cpuUnit.takeDamage(1, null); // null means unknown entity

Assert.assertTrue(cpuUnit.shouldMove());
assertTrue(cpuUnit.shouldMove());
}

@Test
Expand All @@ -78,8 +76,8 @@ public void cpuUnitAttacksBackTheEntityItTookDamageFrom() {

unit.takeDamage(1, humanUnit); // takes damage from the humanUnit

Assert.assertTrue(unit.shouldAttack());
Assert.assertEquals(humanUnit, unit.getEntityToAttack());
assertTrue(unit.shouldAttack());
assertEquals(humanUnit, unit.getEntityToAttack());
}

@Test
Expand Down Expand Up @@ -259,7 +257,7 @@ public void canHarvestWhenHarvesterAndOnHarvestableCell() {
assertThat(harvesterEntityData.isHarvester, is(true));

// make an all 'spice' map, with more resources than the harvester capacity
MapEditor mapEditor = new MapEditor(new DuneTerrainFactory(Mockito.mock(Theme.class)) {
MapEditor mapEditor = new MapEditor(new DuneTerrainFactory(mock(Theme.class)) {
@Override
public int getSpiceAmount() {
return harvesterEntityData.harvestCapacity + 1;
Expand All @@ -285,7 +283,7 @@ public int getSpiceAmount() {
@Test
public void canHarvestIsFalseWhenNotHarvester() {
// make an all spice map
MapEditor mapEditor = new MapEditor(new DuneTerrainFactory(Mockito.mock(Theme.class)));
MapEditor mapEditor = new MapEditor(new DuneTerrainFactory(mock(Theme.class)));
mapEditor.fillMapWithTerrain(map, DuneTerrain.TERRAIN_SPICE);

Unit unit = makeUnit(player, MapCoordinate.create(2, 2), EntitiesData.QUAD);
Expand All @@ -300,7 +298,7 @@ public void returnToRefineryThrowsIllegalArgumentExceptionWhenArgumentIsNotARefi
unit.returnToRefinery(constYard);
fail("Expected illegal argument exception");
} catch (IllegalArgumentException iae) {
Assert.assertEquals("Can only return to refinery type of entity", iae.getMessage());
assertEquals("Can only return to refinery type of entity", iae.getMessage());
}
}

Expand All @@ -312,7 +310,7 @@ public void returnToRefineryThrowsIllegalArgumentExceptionWhenUnitIsNotAHarveste
unit.returnToRefinery(refinery);
fail("Expected illegal state exception");
} catch (IllegalStateException ise) {
Assert.assertEquals("Only harvesters can return to a refinery", ise.getMessage());
assertEquals("Only harvesters can return to a refinery", ise.getMessage());
}
}

Expand All @@ -325,10 +323,10 @@ public void firstHarvesterReturnsToRefinery() {
unit.returnToRefinery(refinery);

Entity who = EnterStructureIntent.instance.getEnterIntentFrom(refinery);
Assert.assertSame(who, unit);
assertSame(who, unit);

Assert.assertTrue(unit.getState() instanceof GoalResolverState);
Assert.assertEquals(unit.getTarget(), refinery.getCoordinate());
assertTrue(unit.getState() instanceof GoalResolverState);
assertEquals(unit.getTarget(), refinery.getCoordinate());
}

@Test
Expand All @@ -342,28 +340,28 @@ public void secondHarvesterMovesToRefinery() {
harvester1.returnToRefinery(refinery);

Entity who = EnterStructureIntent.instance.getEnterIntentFrom(refinery);
Assert.assertSame(who, harvester2);
assertSame(who, harvester2);
}

@Test
public void isCellPassableForMeIsTrueWhenNoOtherUnitIsPresent() {
Unit harvester1 = makeUnit(player, MapCoordinate.create(2, 2), EntitiesData.HARVESTER);
assertTrue(harvester1.isCellPassableForMe(MapCoordinate.create(3, 3)));
Unit harvester = makeUnit(player, MapCoordinate.create(2, 2), EntitiesData.HARVESTER);
assertTrue(harvester.isCellPassableForMe(MapCoordinate.create(3, 3)));
}

@Test
public void isCellPassableForMeIsFalseWhenOtherEntityOccupiesCell() {
Unit harvester1 = makeUnit(player, MapCoordinate.create(2, 2), EntitiesData.HARVESTER);
Structure refinery = makeStructure(player, MapCoordinate.create(3, 3), EntitiesData.REFINERY);
makeStructure(player, MapCoordinate.create(3, 3), EntitiesData.REFINERY);
assertFalse(harvester1.isCellPassableForMe(MapCoordinate.create(3, 3)));
}

@Test
public void isCellPassableForMeIsTrueWhenEntityThatOccupiesCellIsTheEntityToReturnTo() {
Unit harvester1 = makeUnit(player, MapCoordinate.create(2, 2), EntitiesData.HARVESTER);
Unit harvester = makeUnit(player, MapCoordinate.create(2, 2), EntitiesData.HARVESTER);
Structure refinery = makeStructure(player, MapCoordinate.create(3, 3), EntitiesData.REFINERY);
harvester1.returnToRefinery(refinery);
assertTrue(harvester1.isCellPassableForMe(MapCoordinate.create(3, 3)));
harvester.returnToRefinery(refinery);
assertTrue(harvester.isCellPassableForMe(MapCoordinate.create(3, 3)));
}

public static void updateUnitTimesHundredMilis(Unit unit, int times) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/fundynamic/d2tm/math/MapCoordinateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public void distanceInMapCoords() {

@Test
public void equalsTo() {
MapCoordinate mapCoordinate = MapCoordinate.create(10, 10);
Assert.assertEquals(MapCoordinate.create(10, 10), mapCoordinate);
MapCoordinate mapCoordinate = create(10, 10);
Assert.assertEquals(create(10, 10), mapCoordinate);
Assert.assertEquals(Coordinate.create(10*TILE_SIZE, 10*TILE_SIZE).toMapCoordinate(), mapCoordinate);
}

Expand Down

0 comments on commit fe9df6f

Please sign in to comment.