monster #20
2
pom.xml
2
pom.xml
@@ -29,7 +29,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>5.12.0</version>
|
<version>5.20.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
public abstract class Attack {
|
|
||||||
//Namnet och bägge dessa siffror är helt lösryckta
|
|
||||||
private static final String DEFAULT_NAME = "DEFAULT_NAME";
|
|
||||||
private static final double DEFAULT_ENERGY_COST = 5d;
|
|
||||||
private static final double DEFAULT_DAMAGE = 5d;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private double energyCost;
|
|
||||||
private double damage;
|
|
||||||
|
|
||||||
public Attack() {
|
|
||||||
name = DEFAULT_NAME;
|
|
||||||
energyCost = DEFAULT_ENERGY_COST;
|
|
||||||
damage = DEFAULT_DAMAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Attack(String name, double energyCost, double damage) {
|
|
||||||
this.name = name;
|
|
||||||
this.energyCost = energyCost;
|
|
||||||
this.damage = damage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean perform(Character target);
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
import Entity.Position;
|
|
||||||
|
|
||||||
public abstract class Character {
|
|
||||||
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 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 Position position;
|
|
||||||
|
|
||||||
// Hur många varianter på konstruktorn behövs?
|
|
||||||
public Character() {
|
|
||||||
this.health = DEFAULT_HEALTH;
|
|
||||||
this.energy = DEFAULT_ENERGY;
|
|
||||||
this.position = DEFAULT_POSITION;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Jag antar att den som instansierar massa monster i världen ansvarar
|
|
||||||
// för att kolla att "position" har ett tillåtet värde.
|
|
||||||
// Just denna variant är bara för testning i min implementation av Monster
|
|
||||||
public Character(Position position) {
|
|
||||||
this.health = DEFAULT_HEALTH;
|
|
||||||
this.energy = DEFAULT_ENERGY;
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Character(double health, double energy, Position position) {
|
|
||||||
this.health = health;
|
|
||||||
this.energy = energy;
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Returnerar true om attacken gick igenom, annars false
|
|
||||||
abstract boolean attack(Character character);
|
|
||||||
|
|
||||||
public double getHealth() {
|
|
||||||
return health;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHealth(int newHealth) {
|
|
||||||
health = newHealth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getLevel() {
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLevel(int newLevel) {
|
|
||||||
level = newLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getEnergy() {
|
|
||||||
return energy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnergy(double newEnergy) {
|
|
||||||
energy = newEnergy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position getPosition() {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPosition(Position newPosition) {
|
|
||||||
position = newPosition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,10 +4,10 @@ import java.util.*;
|
|||||||
public abstract class Monster {
|
public abstract class Monster {
|
||||||
public static final Position DEFAULT_POSITION = new Position(0,0);
|
public static final Position DEFAULT_POSITION = new Position(0,0);
|
||||||
|
|
||||||
private int health;
|
protected 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
|
protected 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;
|
protected Position position;
|
||||||
private boolean isAlive;
|
protected boolean isAlive;
|
||||||
|
|
||||||
public Monster(int health, int energy, Position position) {
|
public Monster(int health, int energy, Position position) {
|
||||||
this.health = health;
|
this.health = health;
|
||||||
@@ -34,6 +34,10 @@ public abstract class Monster {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAlive() {
|
||||||
|
return isAlive;
|
||||||
|
}
|
||||||
|
|
||||||
abstract void heal();
|
abstract void heal();
|
||||||
|
|
||||||
abstract void takeDamage();
|
abstract void takeDamage();
|
||||||
|
|||||||
@@ -2,11 +2,36 @@ import Entity.Position;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Shade extends Monster {
|
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 static final List<Biomes> habitat = Collections.unmodifiableList(Arrays.asList(Biomes.COAST, Biomes.FOREST, Biomes.GRASSLAND, Biomes.MOUNTAIN));
|
||||||
|
|
||||||
|
private static final int MAX_HEALTH = 20;
|
||||||
|
private static final int MAX_ENERGY = 14;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Shade() {
|
public Shade() {
|
||||||
|
super(MAX_HEALTH, MAX_ENERGY, Monster.DEFAULT_POSITION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void heal() {
|
||||||
|
if (isAlive()) {
|
||||||
|
health += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void takeDamage() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recharge() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTo(Position position) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
import Entity.Position;
|
import Action.*;
|
||||||
|
import Character.*;
|
||||||
|
import Combat.*;
|
||||||
|
import Entity.*;
|
||||||
|
import Inventory.*;
|
||||||
|
import Job.*;
|
||||||
|
import Shared.*;
|
||||||
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import static org.hamcrest.MatcherAssert.*;
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import Entity.Player;
|
|
||||||
|
|
||||||
public class MonsterTest {
|
public class MonsterTest {
|
||||||
|
|
||||||
@@ -15,22 +22,22 @@ public class MonsterTest {
|
|||||||
defaultShade = new Shade(); //Återställer alla värden till default
|
defaultShade = new Shade(); //Återställer alla värden till default
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/*@Test
|
||||||
void monster_cannot_act_after_death() {
|
void monster_cannot_act_after_death() {
|
||||||
defaultShade.kill();
|
defaultShade.kill();
|
||||||
assertThat(false, anyOf(defaultShade.moveTo(new Position(0, 1)), defaultShade.attack(Attacks.CHILL, defaultPlayer)));
|
assertThat(false, anyOf(defaultShade.moveTo(new Position(0, 1)), defaultShade.attack(Attacks.CHILL, defaultPlayer)));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void reaching_zero_health_triggers_death() {
|
void reaching_zero_health_triggers_death() {
|
||||||
defaultShade.setHealth(0);
|
defaultShade.kill();
|
||||||
assertThat(true, is(defaultShade.isAlive()));
|
assertThat(false, equalTo(defaultShade.isAlive()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void monster_cannot_regain_health_after_death() {
|
void monster_cannot_regain_health_after_death() {
|
||||||
defaultShade.kill();
|
defaultShade.kill();
|
||||||
defaultShade.setHealth(10);
|
defaultShade.heal();
|
||||||
assertThat(defaultShade.getHealth(), equalTo(0));
|
assertThat(defaultShade.getHealth(), equalTo(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user