monster #20
@@ -2,19 +2,28 @@ import Entity.Position;
|
||||
import java.util.*;
|
||||
|
||||
public enum MovementPatterns {
|
||||
ONE_STEP_DIAGONALLY(1);
|
||||
ONE_DIAGONAL_STEP(1, 1);
|
||||
|
||||
private int cost;
|
||||
public int cost;
|
||||
private int id;
|
||||
|
||||
MovementPatterns(int cost) {
|
||||
MovementPatterns(int cost, int id) {
|
||||
this.cost = cost;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<Position> getLegalDestinations(Position position) {
|
||||
public List<Position> findLegalDestinations(Position position) {
|
||||
List<Position> legalDestinations = new ArrayList<>();
|
||||
|
||||
switch {
|
||||
case
|
||||
switch(id) {
|
||||
case 1:
|
||||
int x = position.x();
|
||||
int y = position.y();
|
||||
legalDestinations.addAll(Arrays.asList(new Position(x - 1, y + 1), new Position(x + 1, y + 1),
|
||||
new Position(x - 1, y - 1), new Position(x + 1, y - 1)));
|
||||
break;
|
||||
}
|
||||
|
||||
return legalDestinations;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,20 @@ import Entity.Position;
|
||||
import java.util.*;
|
||||
|
||||
public class Shade extends Monster implements CanMove, CanAttack {
|
||||
public static final List<Biomes> habitat = Collections.unmodifiableList(Arrays.asList(Biomes.COAST, Biomes.FOREST, Biomes.GRASSLAND, Biomes.MOUNTAIN));
|
||||
public static final List<Biomes> HABITAT = Collections.unmodifiableList(Arrays.asList(Biomes.COAST, Biomes.FOREST, Biomes.GRASSLAND, Biomes.MOUNTAIN));
|
||||
public static final List<MovementPatterns> MOVES = Collections.unmodifiableList(Arrays.asList(MovementPatterns.ONE_DIAGONAL_STEP));
|
||||
public static final int MAX_HEALTH = 20;
|
||||
public static final int MAX_ENERGY = 14;
|
||||
|
||||
private static final int HEALTH_PER_HEAL = 2;
|
||||
private static final int ENERGY_COST_PER_HEAL = 1;
|
||||
|
||||
private Random random = new Random();
|
||||
private List<Position> validDestinations = new ArrayList<>();
|
||||
|
||||
public Shade() {
|
||||
super(MAX_HEALTH, MAX_ENERGY, Monster.DEFAULT_POSITION);
|
||||
updateDestinations(position);
|
||||
}
|
||||
|
||||
public void heal() {
|
||||
@@ -46,8 +51,14 @@ public class Shade extends Monster implements CanMove, CanAttack {
|
||||
}
|
||||
|
||||
public boolean move() {
|
||||
if (isDead()) {
|
||||
return false;
|
||||
}
|
||||
position = validDestinations.get(random.nextInt(validDestinations.size()));
|
||||
updateDestinations(position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean moveTo(Position position) {
|
||||
if (isDead()) {
|
||||
@@ -62,4 +73,11 @@ public class Shade extends Monster implements CanMove, CanAttack {
|
||||
health = MAX_HEALTH;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDestinations(Position position) {
|
||||
validDestinations.clear();
|
||||
for (MovementPatterns move : MOVES) {
|
||||
validDestinations.addAll(move.findLegalDestinations(position));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ public class MonsterTest {
|
||||
assertThrows(IllegalStateException.class, () -> defaultShade.heal());
|
||||
}
|
||||
|
||||
//Är denna för lång?
|
||||
@Test
|
||||
void method_move_places_monster_in_legal_position() {
|
||||
Position startingPosition = defaultShade.getPosition();
|
||||
@@ -57,11 +58,15 @@ public class MonsterTest {
|
||||
List<MovementPatterns> moves = defaultShade.MOVES;
|
||||
|
||||
for (MovementPatterns move : moves) {
|
||||
legalDestinations.addAll(move.getLegalDestinations(startingPosition));
|
||||
legalDestinations.addAll(move.findLegalDestinations(startingPosition));
|
||||
}
|
||||
|
||||
defaultShade.move();
|
||||
|
||||
assertThat(legalDestinations, hasItem(defaultShade.getPosition()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void monster_cannot_do_anything_when_out_of_energy() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user