equipments #22

Merged
viud3133 merged 40 commits from equipments into main 2025-10-30 12:09:43 +01:00
6 changed files with 54 additions and 19 deletions
Showing only changes of commit 7d67c7db64 - Show all commits

View 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;
}
}

View File

@@ -0,0 +1,8 @@
import Entity.Position;
//Är detta ett ok namn?
public interface CanMove {
abstract boolean move();
abstract boolean moveTo(Position position);
}

View File

@@ -1,7 +1,6 @@
import Entity.Position; import Entity.*;
import java.util.*;
public abstract class Monster { public abstract class Monster implements CanMove {
public static final Position DEFAULT_POSITION = new Position(0,0); public static final Position DEFAULT_POSITION = new Position(0,0);
protected int health; protected int health;
@@ -39,14 +38,14 @@ public abstract class Monster {
return isAlive; return isAlive;
} }
public boolean isDead() {
return !isAlive;
}
abstract void heal(); abstract void heal();
abstract void takeDamage(int amount); abstract void takeDamage(int amount);
abstract void recharge(); abstract boolean performAttack(Attacks attack, Player player);
abstract void move();
abstract void moveTo(Position position);
} }

View File

@@ -0,0 +1,9 @@
public enum MovementPatterns {
ONE_STEP_DIAGONALLY(1);
private int cost;
MovementPatterns(int cost) {
this.cost = cost;
}
}

View File

@@ -1,7 +1,8 @@
import Entity.Player;
import Entity.Position; import Entity.Position;
import java.util.*; 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 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_HEALTH = 20;
public static final int MAX_ENERGY = 14; public static final int MAX_ENERGY = 14;
@@ -14,7 +15,7 @@ public class Shade extends Monster {
} }
public void heal() { public void heal() {
if (!isAlive) { if (isDead()) {
throw new IllegalStateException("This shade is dead"); throw new IllegalStateException("This shade is dead");
} }
if (health < MAX_HEALTH) { if (health < MAX_HEALTH) {
@@ -28,7 +29,6 @@ public class Shade extends Monster {
if (amount < 0) { if (amount < 0) {
throw new IllegalArgumentException("'amount' must be a positive integer"); throw new IllegalArgumentException("'amount' must be a positive integer");
} }
if (health - amount <= 0) { if (health - amount <= 0) {
kill(); kill();
} }
@@ -37,16 +37,24 @@ public class Shade extends Monster {
} }
} }
public void recharge() { public boolean performAttack(Attacks attack, Player player) {
if (isDead()) {
return false;
} }
public void move() { return true;
} }
public void moveTo(Position position) { public boolean move() {
return false;
}
public boolean moveTo(Position position) {
if (isDead()) {
return false;
}
return true;
} }
private void enforceHealthMaximum() { private void enforceHealthMaximum() {

View File

@@ -23,11 +23,11 @@ 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(is(defaultShade.moveTo(new Position(0, 1))), is(defaultShade.performAttack(Attacks.CHILL, defaultPlayer))));
}*/ }
@Test @Test
void reaching_zero_health_triggers_death() { void reaching_zero_health_triggers_death() {
@@ -36,7 +36,7 @@ public class MonsterTest {
} }
@Test @Test
void monster_cannot_regain_health_after_death() { void monster_cannot_heal_after_death() {
defaultShade.kill(); defaultShade.kill();
assertThrows(IllegalStateException.class, () -> defaultShade.heal()); assertThrows(IllegalStateException.class, () -> defaultShade.heal());
} }