equipments #22

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

View File

@@ -13,6 +13,7 @@
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
@@ -33,5 +34,5 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>

11
src/main/java/Action.java Normal file
View File

@@ -0,0 +1,11 @@
public abstract class Action {
private int cost;
public Action(int cost) {
}
public int getCost() {
return cost;
}
}

View File

@@ -0,0 +1,9 @@
public enum Actions {
HEAL(2);
private final int cost;
Actions(int cost) {
this.cost = cost;
}
}

View File

@@ -0,0 +1,8 @@
public class Healing extends Action {
private int healthRegenerated;
public Healing() {
super(2);
}
}

View File

@@ -19,6 +19,7 @@ public abstract class Monster {
public void kill() {
health = 0;
energy = 0;
isAlive = false;
}
@@ -40,7 +41,7 @@ public abstract class Monster {
abstract void heal();
abstract void takeDamage();
abstract void takeDamage(int amount);
abstract void recharge();

View File

@@ -3,24 +3,38 @@ import java.util.*;
public class Shade extends Monster {
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_ENERGY = 14;
private static final int MAX_HEALTH = 20;
private static final int MAX_ENERGY = 14;
private static final int HEALTH_PER_HEAL = 2;
private static final int ENERGY_COST_PER_HEAL = 1;
public Shade() {
super(MAX_HEALTH, MAX_ENERGY, Monster.DEFAULT_POSITION);
}
public void heal() {
if (isAlive()) {
health += 2;
if (!isAlive) {
throw new IllegalStateException("This shade is dead");
}
if (health < MAX_HEALTH) {
health += HEALTH_PER_HEAL;
energy -= ENERGY_COST_PER_HEAL;
enforceHealthMaximum();
}
}
public void takeDamage() {
public void takeDamage(int amount) {
if (amount < 0) {
throw new IllegalArgumentException("'amount' must be a positive integer");
}
if (health - amount <= 0) {
kill();
}
else {
health =- amount;
}
}
public void recharge() {
@@ -34,4 +48,10 @@ public class Shade extends Monster {
public void moveTo(Position position) {
}
private void enforceHealthMaximum() {
if (health > MAX_HEALTH) {
health = MAX_HEALTH;
}
}
}

View File

@@ -9,6 +9,7 @@ import Shared.*;
import org.junit.jupiter.api.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
@@ -30,14 +31,13 @@ public class MonsterTest {
@Test
void reaching_zero_health_triggers_death() {
defaultShade.kill();
defaultShade.takeDamage(Shade.MAX_HEALTH);
assertThat(false, equalTo(defaultShade.isAlive()));
}
@Test
void monster_cannot_regain_health_after_death() {
defaultShade.kill();
defaultShade.heal();
assertThat(defaultShade.getHealth(), equalTo(0));
assertThrows(IllegalStateException.class, () -> defaultShade.heal());
}
}