monster #20
@@ -19,4 +19,6 @@ public abstract class Attack {
|
||||
this.energyCost = energyCost;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public abstract boolean perform(Character target);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
//Vill inte göra så mycket med den här klassen, då jag vill påverka implementeringen av Player så lite som möjligt
|
||||
import Entity.Position;
|
||||
|
||||
public abstract class Character {
|
||||
private static final double DEFAULT_HEALTH = 50d;
|
||||
private static final double DEFAULT_LEVEL = 1.0;
|
||||
private static final double DEFAULT_ENERGY = 50d; //Detta borde kanske egentligen beräknas och sättas automatiskt genom en algoritm som tar health och level i beaktskap?? Eller något sådant
|
||||
private static final Position DEFAULT_POSITION = new Position(0,0); //Är detta en bra idé?? Mest för att kunna ha defaultkonstruktor
|
||||
private static final double DEFAULT_ENERGY = 20d;
|
||||
private static final Position DEFAULT_POSITION = new Position(0,0);
|
||||
|
||||
// Borde jag bara sätta allt till default direkt här????
|
||||
private double health;
|
||||
private double level;
|
||||
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.level = DEFAULT_LEVEL;
|
||||
this.energy = DEFAULT_ENERGY;
|
||||
this.position = DEFAULT_POSITION;
|
||||
}
|
||||
@@ -24,22 +21,18 @@ public abstract class Character {
|
||||
// Just denna variant är bara för testning i min implementation av Monster
|
||||
public Character(Position position) {
|
||||
this.health = DEFAULT_HEALTH;
|
||||
this.level = DEFAULT_LEVEL;
|
||||
this.energy = DEFAULT_ENERGY;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Character(double health, double level, double energy, Position position) {
|
||||
public Character(double health, double energy, Position position) {
|
||||
this.health = health;
|
||||
this.level = level;
|
||||
this.energy = energy;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
//Returnerar true om attacken gick igenom, annars false
|
||||
//Tänker att positionen som skickas in är karaktärens egna
|
||||
//Kommer antagligen behöva diverse hjälpmetoder i implementeringen då det är många krav som måste uppfyllas för att attacken ska gå igenom
|
||||
abstract boolean attack(Position position, Character character);
|
||||
abstract boolean attack(Character character);
|
||||
|
||||
public double getHealth() {
|
||||
return health;
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
import Entity.Position;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class Monster extends Character{
|
||||
public abstract class Monster {
|
||||
|
||||
private final List<Biomes> habitat = new ArrayList<>();
|
||||
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 Position position;
|
||||
private List<Biomes> habitat;
|
||||
|
||||
public Monster() {
|
||||
habitat.addAll(Arrays.asList(Biomes.GRASSLAND, Biomes.MOUNTAIN, Biomes.COAST, Biomes.FOREST));
|
||||
this.health = DEFAULT_HEALTH;
|
||||
this.energy = DEFAULT_ENERGY;
|
||||
this.position = DEFAULT_POSITION;
|
||||
this.habitat.addAll(DEFAULT_HABITAT);
|
||||
}
|
||||
|
||||
public Monster(Position position) {
|
||||
super(position);
|
||||
habitat.addAll(Arrays.asList(Biomes.GRASSLAND, Biomes.MOUNTAIN, Biomes.COAST, Biomes.FOREST));
|
||||
this-health = DEFAULT_HEALTH;
|
||||
this.energy = DEFAULT_ENERGY;
|
||||
this.position = position;
|
||||
this.habitat.addAll(DEFAULT_HABITAT);
|
||||
}
|
||||
|
||||
public Monster(double health, double level, double energy, Position position) {
|
||||
|
||||
@@ -1,50 +1,35 @@
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.*;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import Entity.Player;
|
||||
|
||||
public class MonsterTest {
|
||||
|
||||
@Test
|
||||
void monster_cannot_attack_when_dead() {
|
||||
/*
|
||||
Monster someMonster = new Monster();
|
||||
someMonster.setHealth(-5d);
|
||||
Assert(false, someMonster.attack(someMonster.getPosition(), character));
|
||||
*/
|
||||
private Shade defaultShade;
|
||||
private Player defaultPlayer = mock(Player.class);
|
||||
|
||||
@BeforeEach
|
||||
void reset() {
|
||||
defaultShade = new Shade(); //Återställer alla värden till default
|
||||
}
|
||||
|
||||
@Test
|
||||
void monster_cannot_be_attacked_when_dead() {
|
||||
/*
|
||||
Monster attackingMonster = new Monster();
|
||||
Monster deadMonster = new Monster();
|
||||
deadMonster.setHealth(-4d);
|
||||
Assert(false, attackingMonster.attack(attackingMonster.getPosition(), deadMonster));
|
||||
*/
|
||||
void monster_cannot_act_after_death() {
|
||||
defaultShade.setHealth(0);
|
||||
assertThat(false, anyOf(defaultShade.moveTo(0, 1), defaultShade.attack(Attacks.CHILL, defaultPlayer)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void monster_cannot_attack_character_at_different_position() {
|
||||
/*
|
||||
Monster monsterAtOnePosition = new Monster(new Position(0,0));
|
||||
Monster monsterAtDifferentPosition = new Monster(new Position(1,1));
|
||||
Assert(false, monsterAtOnePosition.attack(monsterAtOnePosition.getPosition(), monsterAtDifferentPosition);
|
||||
*/
|
||||
void reaching_zero_health_triggers_death() {
|
||||
defaultShade.setHealth(0);
|
||||
assertThat(true, is(defaultShade.isAlive()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void monster_is_instantiated_correctly_from_default_constructor() {
|
||||
/*
|
||||
AssertAll????
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
void monster_is_instantiated_correctly_from_position_only_constructor() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void monster_is_instantiated_correctly_from_full_constructor() {
|
||||
|
||||
void monster_cannot_regain_health_after_death() {
|
||||
defaultShade.setHealth(0);
|
||||
defaultShade.setHealth(10d);
|
||||
assertThat(defaultShade.getHealth(), equalTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user