monster #20
@@ -2,43 +2,46 @@ import Entity.Position;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class Monster {
|
||||
public static final Position DEFAULT_POSITION = new Position(0,0);
|
||||
|
||||
private static final double DEFAULT_HEALTH = 50d;
|
||||
private static final double DEFAULT_ENERGY = 20d;
|
||||
private static final Position DEFAULT_POSITION = new Position(0,0);
|
||||
private static final List<Biomes> DEFAULT_HABITAT = Arrays.asList(Biomes.GRASSLAND, Biomes.MOUNTAIN, Biomes.COAST, Biomes.FOREST);
|
||||
|
||||
private double health;
|
||||
private double energy; //Borde kanske beräknas genom en algoritm istället för att kunna sättas i konstruktorn... Så det alltid blir balanserat
|
||||
private int health;
|
||||
private int energy; //Borde kanske beräknas genom en algoritm istället för att kunna sättas i konstruktorn... Så det alltid blir balanserat
|
||||
private Position position;
|
||||
private List<Biomes> habitat;
|
||||
private boolean isAlive;
|
||||
|
||||
public Monster() {
|
||||
this.health = DEFAULT_HEALTH;
|
||||
this.energy = DEFAULT_ENERGY;
|
||||
this.position = DEFAULT_POSITION;
|
||||
this.habitat.addAll(DEFAULT_HABITAT);
|
||||
}
|
||||
|
||||
public Monster(Position position) {
|
||||
this-health = DEFAULT_HEALTH;
|
||||
this.energy = DEFAULT_ENERGY;
|
||||
public Monster(int health, int energy, Position position) {
|
||||
this.health = health;
|
||||
this.energy = energy;
|
||||
this.position = position;
|
||||
this.habitat.addAll(DEFAULT_HABITAT);
|
||||
|
||||
isAlive = true;
|
||||
}
|
||||
|
||||
public Monster(double health, double level, double energy, Position position) {
|
||||
super(health, level, energy, position);
|
||||
habitat.addAll(Arrays.asList(Biomes.GRASSLAND, Biomes.MOUNTAIN, Biomes.COAST, Biomes.FOREST));
|
||||
public void kill() {
|
||||
health = 0;
|
||||
isAlive = false;
|
||||
}
|
||||
|
||||
public Monster(double health, double level, double energy, Position position, List<Biomes> habitat) {
|
||||
super(health, level, energy, position);
|
||||
this.habitat.addAll(habitat);
|
||||
public int getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
//Är detta bra??? Med unmodifiableList dvs
|
||||
public List<Biomes> getHabitat() {
|
||||
return Collections.unmodifiableList(habitat);
|
||||
public int getEnergy() {
|
||||
return energy;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
abstract void heal();
|
||||
|
||||
abstract void takeDamage();
|
||||
|
||||
abstract void recharge();
|
||||
|
||||
abstract void move();
|
||||
|
||||
abstract void moveTo(Position position);
|
||||
|
||||
}
|
||||
|
||||
12
src/main/java/Shade.java
Normal file
12
src/main/java/Shade.java
Normal file
@@ -0,0 +1,12 @@
|
||||
import Entity.Position;
|
||||
import java.util.*;
|
||||
|
||||
public class Shade extends Monster {
|
||||
public static final int MAX_HEALTH = 20;
|
||||
public static final int MAX_ENERGY = 14;
|
||||
public static final List<Biomes> habitat = Collections.unmodifiableList(Arrays.asList(Biomes.COAST, Biomes.FOREST, Biomes.GRASSLAND, Biomes.MOUNTAIN));
|
||||
|
||||
public Shade() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import Entity.Position;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
@@ -16,8 +17,8 @@ public class MonsterTest {
|
||||
|
||||
@Test
|
||||
void monster_cannot_act_after_death() {
|
||||
defaultShade.setHealth(0);
|
||||
assertThat(false, anyOf(defaultShade.moveTo(0, 1), defaultShade.attack(Attacks.CHILL, defaultPlayer)));
|
||||
defaultShade.kill();
|
||||
assertThat(false, anyOf(defaultShade.moveTo(new Position(0, 1)), defaultShade.attack(Attacks.CHILL, defaultPlayer)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -28,8 +29,8 @@ public class MonsterTest {
|
||||
|
||||
@Test
|
||||
void monster_cannot_regain_health_after_death() {
|
||||
defaultShade.setHealth(0);
|
||||
defaultShade.setHealth(10d);
|
||||
defaultShade.kill();
|
||||
defaultShade.setHealth(10);
|
||||
assertThat(defaultShade.getHealth(), equalTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user