monster #20
11
src/main/java/Attacks.java
Normal file
11
src/main/java/Attacks.java
Normal file
@@ -0,0 +1,11 @@
|
||||
public enum Attacks {
|
||||
CHILL(3, 2);
|
||||
|
||||
private int damage;
|
||||
private int cost;
|
||||
|
||||
Attacks(int damage, int cost) {
|
||||
this.damage = damage;
|
||||
this.cost = cost;
|
||||
}
|
||||
}
|
||||
8
src/main/java/CanMove.java
Normal file
8
src/main/java/CanMove.java
Normal file
@@ -0,0 +1,8 @@
|
||||
import Entity.Position;
|
||||
//Är detta ett ok namn?
|
||||
public interface CanMove {
|
||||
|
||||
abstract boolean move();
|
||||
|
||||
abstract boolean moveTo(Position position);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import Entity.Position;
|
||||
import java.util.*;
|
||||
import Entity.*;
|
||||
|
||||
public abstract class Monster {
|
||||
public abstract class Monster implements CanMove {
|
||||
public static final Position DEFAULT_POSITION = new Position(0,0);
|
||||
|
||||
protected int health;
|
||||
@@ -39,14 +38,14 @@ public abstract class Monster {
|
||||
return isAlive;
|
||||
}
|
||||
|
||||
public boolean isDead() {
|
||||
return !isAlive;
|
||||
}
|
||||
|
||||
abstract void heal();
|
||||
|
||||
abstract void takeDamage(int amount);
|
||||
|
||||
abstract void recharge();
|
||||
|
||||
abstract void move();
|
||||
|
||||
abstract void moveTo(Position position);
|
||||
abstract boolean performAttack(Attacks attack, Player player);
|
||||
|
||||
}
|
||||
|
||||
9
src/main/java/MovementPatterns.java
Normal file
9
src/main/java/MovementPatterns.java
Normal file
@@ -0,0 +1,9 @@
|
||||
public enum MovementPatterns {
|
||||
ONE_STEP_DIAGONALLY(1);
|
||||
|
||||
private int cost;
|
||||
|
||||
MovementPatterns(int cost) {
|
||||
this.cost = cost;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import Entity.Player;
|
||||
import Entity.Position;
|
||||
import java.util.*;
|
||||
|
||||
public class Shade extends Monster {
|
||||
public class Shade extends Monster implements CanMove {
|
||||
public static final List<Biomes> habitat = Collections.unmodifiableList(Arrays.asList(Biomes.COAST, Biomes.FOREST, Biomes.GRASSLAND, Biomes.MOUNTAIN));
|
||||
public static final int MAX_HEALTH = 20;
|
||||
public static final int MAX_ENERGY = 14;
|
||||
@@ -14,7 +15,7 @@ public class Shade extends Monster {
|
||||
}
|
||||
|
||||
public void heal() {
|
||||
if (!isAlive) {
|
||||
if (isDead()) {
|
||||
throw new IllegalStateException("This shade is dead");
|
||||
}
|
||||
if (health < MAX_HEALTH) {
|
||||
@@ -28,7 +29,6 @@ public class Shade extends Monster {
|
||||
if (amount < 0) {
|
||||
throw new IllegalArgumentException("'amount' must be a positive integer");
|
||||
}
|
||||
|
||||
if (health - amount <= 0) {
|
||||
kill();
|
||||
}
|
||||
@@ -37,16 +37,24 @@ public class Shade extends Monster {
|
||||
}
|
||||
}
|
||||
|
||||
public void recharge() {
|
||||
public boolean performAttack(Attacks attack, Player player) {
|
||||
if (isDead()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void move() {
|
||||
|
||||
public boolean move() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void moveTo(Position position) {
|
||||
public boolean moveTo(Position position) {
|
||||
if (isDead()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void enforceHealthMaximum() {
|
||||
|
||||
@@ -23,11 +23,11 @@ public class MonsterTest {
|
||||
defaultShade = new Shade(); //Återställer alla värden till default
|
||||
}
|
||||
|
||||
/*@Test
|
||||
@Test
|
||||
void monster_cannot_act_after_death() {
|
||||
defaultShade.kill();
|
||||
assertThat(false, anyOf(defaultShade.moveTo(new Position(0, 1)), defaultShade.attack(Attacks.CHILL, defaultPlayer)));
|
||||
}*/
|
||||
assertThat(false, anyOf(is(defaultShade.moveTo(new Position(0, 1))), is(defaultShade.performAttack(Attacks.CHILL, defaultPlayer))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reaching_zero_health_triggers_death() {
|
||||
@@ -36,7 +36,7 @@ public class MonsterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void monster_cannot_regain_health_after_death() {
|
||||
void monster_cannot_heal_after_death() {
|
||||
defaultShade.kill();
|
||||
assertThrows(IllegalStateException.class, () -> defaultShade.heal());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user