equipments #22
@@ -77,10 +77,11 @@ public class Shade extends Monster implements CanMove, CanAttack {
|
||||
}
|
||||
|
||||
public boolean move(World world) {
|
||||
updateDestinations(position, world);
|
||||
|
||||
if (isDead()) {
|
||||
return false;
|
||||
}
|
||||
updateDestinations(position, world);
|
||||
if (validDestinations.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -90,15 +91,18 @@ public class Shade extends Monster implements CanMove, CanAttack {
|
||||
}
|
||||
|
||||
public boolean moveTo(Position destination, World world) {
|
||||
updateDestinations(position, world);
|
||||
|
||||
if (isDead()) {
|
||||
return false;
|
||||
}
|
||||
if (playerIsAtPosition(destination, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (validDestinations.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
position = destination;
|
||||
updateDestinations(position, world);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package Monster;
|
||||
import Entity.Entity;
|
||||
import Entity.Player;
|
||||
import Entity.Position;
|
||||
import World.World;
|
||||
import World.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -82,10 +82,11 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
||||
}
|
||||
|
||||
public boolean move(World world) {
|
||||
updateDestinations(position, world);
|
||||
|
||||
if (isDead()) {
|
||||
return false;
|
||||
}
|
||||
updateDestinations(position, world);
|
||||
if (validDestinations.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -95,18 +96,18 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
||||
}
|
||||
|
||||
public boolean moveTo(Position destination, World world) {
|
||||
updateDestinations(position, world);
|
||||
|
||||
if (isDead()) {
|
||||
return false;
|
||||
}
|
||||
if (playerIsAtPosition(destination, world)) {
|
||||
return false;
|
||||
}
|
||||
if (tileHasWrongHabitat(destination, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (validDestinations.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
position = destination;
|
||||
updateDestinations(position, world);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,7 +117,7 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
||||
if (move.cost <= energy) {
|
||||
List<Position> destinations = move.findLegalDestinations(position);
|
||||
for (Position destination : destinations) {
|
||||
if (noPlayerIsAtPosition(destination, world)) {
|
||||
if (tileHasWrongHabitat(destination, world)) {
|
||||
validDestinations.add(destination);
|
||||
}
|
||||
}
|
||||
@@ -124,22 +125,6 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean playerIsAtPosition(Position position, World world) {
|
||||
List<Entity> entitiesAtPosition = world.getPositionEntityMap().get(position);
|
||||
if (isNull(entitiesAtPosition)) {
|
||||
return false;
|
||||
}
|
||||
for (Entity entity : entitiesAtPosition) {
|
||||
if (entity instanceof Player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean noPlayerIsAtPosition(Position position, World world) {
|
||||
return !playerIsAtPosition(position, world);
|
||||
}
|
||||
|
||||
private void enforceHealthValueBoundries() {
|
||||
if (health > MAX_HEALTH) {
|
||||
@@ -164,6 +149,14 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
||||
}
|
||||
|
||||
private boolean tileHasWrongHabitat(Position position, World world) {
|
||||
return !HABITAT.contains(world.getTileAtPosition(position).getBiome());
|
||||
Tile destinationTile = world.getTileAtPosition(position);
|
||||
if (Objects.isNull(destinationTile)) {
|
||||
return false;
|
||||
}
|
||||
boolean hasWrongBiome = !HABITAT.contains(destinationTile.getBiome());
|
||||
if (Objects.isNull(hasWrongBiome)) {
|
||||
return false;
|
||||
}
|
||||
return hasWrongBiome;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
||||
public class MonsterTest {
|
||||
|
||||
private Shade defaultShade;
|
||||
|
||||
Reference in New Issue
Block a user