equipments #22
@@ -7,6 +7,7 @@ import static java.util.Objects.*;
|
|||||||
public class Shade extends Monster implements CanMove, CanAttack {
|
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 List<MovementPatterns> MOVES = Collections.unmodifiableList(Arrays.asList(MovementPatterns.ONE_DIAGONAL_STEP));
|
||||||
|
public static final List<Attacks> ATTACKS = Collections.unmodifiableList(Arrays.asList(Attacks.CHILL));
|
||||||
public static final int MAX_HEALTH = 20;
|
public static final int MAX_HEALTH = 20;
|
||||||
public static final int MAX_ENERGY = 14;
|
public static final int MAX_ENERGY = 14;
|
||||||
|
|
||||||
@@ -68,7 +69,10 @@ public class Shade extends Monster implements CanMove, CanAttack {
|
|||||||
if (attack.cost > energy) {
|
if (attack.cost > energy) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (attackIsNotInArsenal(attack)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
player.setHealth(player.getHealth() - attack.cost);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,4 +150,8 @@ public class Shade extends Monster implements CanMove, CanAttack {
|
|||||||
private boolean noPlayerIsAtPosition(Position position, World world) {
|
private boolean noPlayerIsAtPosition(Position position, World world) {
|
||||||
return !playerIsAtPosition(position, world);
|
return !playerIsAtPosition(position, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean attackIsNotInArsenal(Attacks attack) {
|
||||||
|
return !ATTACKS.contains(attack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import static java.util.Objects.isNull;
|
|||||||
public class Troll extends Monster implements CanMove, CanAttack {
|
public class Troll extends Monster implements CanMove, CanAttack {
|
||||||
public static final List<Biomes> HABITAT = Collections.unmodifiableList(Arrays.asList(Biomes.FOREST, Biomes.MOUNTAIN));
|
public static final List<Biomes> HABITAT = Collections.unmodifiableList(Arrays.asList(Biomes.FOREST, Biomes.MOUNTAIN));
|
||||||
public static final List<MovementPatterns> MOVES = Collections.unmodifiableList(Arrays.asList(MovementPatterns.ONE_DIAGONAL_STEP, MovementPatterns.TWO_STEPS_IN_STRAIGHT_LINE));
|
public static final List<MovementPatterns> MOVES = Collections.unmodifiableList(Arrays.asList(MovementPatterns.ONE_DIAGONAL_STEP, MovementPatterns.TWO_STEPS_IN_STRAIGHT_LINE));
|
||||||
|
public static final List<Attacks> ATTACKS = Collections.unmodifiableList(Arrays.asList(Attacks.STOMP));
|
||||||
public static final int MAX_HEALTH = 80;
|
public static final int MAX_HEALTH = 80;
|
||||||
public static final int MAX_ENERGY = 100;
|
public static final int MAX_ENERGY = 100;
|
||||||
|
|
||||||
@@ -73,7 +74,10 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
|||||||
if (attack.cost > energy) {
|
if (attack.cost > energy) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (attackIsNotInArsenal(attack)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
player.setHealth(player.getHealth() - attack.cost);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,4 +155,8 @@ public class Troll extends Monster implements CanMove, CanAttack {
|
|||||||
energy = MIN_ENERGY;
|
energy = MIN_ENERGY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean attackIsNotInArsenal(Attacks attack) {
|
||||||
|
return !ATTACKS.contains(attack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,8 +173,23 @@ public class MonsterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void use_of_attack_not_in_arsenal_is_rejected() {
|
void attack_rejected_when_not_in_arsenal_troll() {
|
||||||
|
assertThat(false, equalTo(defaultTroll.performAttack(Attacks.CHILL, mockPlayer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void attack_rejected_when_not_in_arsenal_shade() {
|
||||||
|
assertThat(false, equalTo(defaultShade.performAttack(Attacks.STOMP, mockPlayer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void troll_can_attack_player() {
|
||||||
|
assertThat(true, equalTo(defaultTroll.performAttack(Attacks.STOMP, mockPlayer)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shade_can_attack_player() {
|
||||||
|
assertThat(true, equalTo(defaultShade.performAttack(Attacks.CHILL, mockPlayer)));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user