equipments #22

Merged
viud3133 merged 40 commits from equipments into main 2025-10-30 12:09:43 +01:00
3 changed files with 48 additions and 32 deletions
Showing only changes of commit 5788f4210a - Show all commits

View File

@@ -2,43 +2,46 @@ import Entity.Position;
import java.util.*; import java.util.*;
public abstract class Monster { public abstract class Monster {
public static final Position DEFAULT_POSITION = new Position(0,0);
private static final double DEFAULT_HEALTH = 50d; private int health;
private static final double DEFAULT_ENERGY = 20d; 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 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 Position position;
private List<Biomes> habitat; private boolean isAlive;
public Monster() { public Monster(int health, int energy, Position position) {
this.health = DEFAULT_HEALTH; this.health = health;
this.energy = DEFAULT_ENERGY; this.energy = energy;
this.position = DEFAULT_POSITION;
this.habitat.addAll(DEFAULT_HABITAT);
}
public Monster(Position position) {
this-health = DEFAULT_HEALTH;
this.energy = DEFAULT_ENERGY;
this.position = position; this.position = position;
this.habitat.addAll(DEFAULT_HABITAT);
isAlive = true;
} }
public Monster(double health, double level, double energy, Position position) { public void kill() {
super(health, level, energy, position); health = 0;
habitat.addAll(Arrays.asList(Biomes.GRASSLAND, Biomes.MOUNTAIN, Biomes.COAST, Biomes.FOREST)); isAlive = false;
} }
public Monster(double health, double level, double energy, Position position, List<Biomes> habitat) { public int getHealth() {
super(health, level, energy, position); return health;
this.habitat.addAll(habitat);
} }
//Är detta bra??? Med unmodifiableList dvs public int getEnergy() {
public List<Biomes> getHabitat() { return energy;
return Collections.unmodifiableList(habitat);
} }
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
View 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() {
}
}

View File

@@ -1,3 +1,4 @@
import Entity.Position;
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.*;
@@ -16,8 +17,8 @@ public class MonsterTest {
@Test @Test
void monster_cannot_act_after_death() { void monster_cannot_act_after_death() {
defaultShade.setHealth(0); defaultShade.kill();
assertThat(false, anyOf(defaultShade.moveTo(0, 1), defaultShade.attack(Attacks.CHILL, defaultPlayer))); assertThat(false, anyOf(defaultShade.moveTo(new Position(0, 1)), defaultShade.attack(Attacks.CHILL, defaultPlayer)));
} }
@Test @Test
@@ -28,8 +29,8 @@ public class MonsterTest {
@Test @Test
void monster_cannot_regain_health_after_death() { void monster_cannot_regain_health_after_death() {
defaultShade.setHealth(0); defaultShade.kill();
defaultShade.setHealth(10d); defaultShade.setHealth(10);
assertThat(defaultShade.getHealth(), equalTo(0)); assertThat(defaultShade.getHealth(), equalTo(0));
} }
} }