monster #20
@@ -101,6 +101,9 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
||||
if (playerIsAtPosition(destination, world)) {
|
||||
return false;
|
||||
}
|
||||
if (tileHasWrongHabitat(position, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
position = destination;
|
||||
updateDestinations(position, world);
|
||||
@@ -159,4 +162,8 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
||||
private boolean attackIsNotInArsenal(Attacks attack) {
|
||||
return !ATTACKS.contains(attack);
|
||||
}
|
||||
|
||||
private boolean tileHasWrongHabitat(Position position, World world) {
|
||||
return !HABITAT.contains(world.getTileAtPosition(position).getBiome());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,11 +195,14 @@ public class MonsterTest {
|
||||
|
||||
@Test
|
||||
void troll_wont_move_to_tile_with_wrong_biome() {
|
||||
Position destination = new Position(1, 3);
|
||||
when(mockTile.getBiome()).thenReturn(Biomes.COAST);
|
||||
when(mockWorld.getTileAtPosition(destination)).thenReturn(mockTile);
|
||||
Position destination = new Position(1, 3);
|
||||
|
||||
assertThat(false, equalTo(defaultTroll.moveTo(destination, mockWorld)));
|
||||
worldGenerator.randomWorldGeneration();
|
||||
World world = worldGenerator.getWorld();
|
||||
world.addTile(mockTile, destination);
|
||||
|
||||
assertThat(defaultTroll.moveTo(destination, world), equalTo(false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user