equipments #22
3
pom.xml
3
pom.xml
@@ -13,6 +13,7 @@
|
|||||||
<maven.compiler.target>23</maven.compiler.target>
|
<maven.compiler.target>23</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
@@ -33,5 +34,5 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
11
src/main/java/Action.java
Normal file
11
src/main/java/Action.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
public abstract class Action {
|
||||||
|
private int cost;
|
||||||
|
|
||||||
|
public Action(int cost) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCost() {
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/main/java/Actions.java
Normal file
9
src/main/java/Actions.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
public enum Actions {
|
||||||
|
HEAL(2);
|
||||||
|
|
||||||
|
private final int cost;
|
||||||
|
|
||||||
|
Actions(int cost) {
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/main/java/Healing.java
Normal file
8
src/main/java/Healing.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
public class Healing extends Action {
|
||||||
|
private int healthRegenerated;
|
||||||
|
|
||||||
|
public Healing() {
|
||||||
|
super(2);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ public abstract class Monster {
|
|||||||
|
|
||||||
public void kill() {
|
public void kill() {
|
||||||
health = 0;
|
health = 0;
|
||||||
|
energy = 0;
|
||||||
isAlive = false;
|
isAlive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ public abstract class Monster {
|
|||||||
|
|
||||||
abstract void heal();
|
abstract void heal();
|
||||||
|
|
||||||
abstract void takeDamage();
|
abstract void takeDamage(int amount);
|
||||||
|
|
||||||
abstract void recharge();
|
abstract void recharge();
|
||||||
|
|
||||||
|
|||||||
@@ -3,24 +3,38 @@ import java.util.*;
|
|||||||
|
|
||||||
public class Shade extends Monster {
|
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 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 HEALTH_PER_HEAL = 2;
|
||||||
private static final int MAX_ENERGY = 14;
|
private static final int ENERGY_COST_PER_HEAL = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Shade() {
|
public Shade() {
|
||||||
super(MAX_HEALTH, MAX_ENERGY, Monster.DEFAULT_POSITION);
|
super(MAX_HEALTH, MAX_ENERGY, Monster.DEFAULT_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void heal() {
|
public void heal() {
|
||||||
if (isAlive()) {
|
if (!isAlive) {
|
||||||
health += 2;
|
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() {
|
public void recharge() {
|
||||||
@@ -34,4 +48,10 @@ public class Shade extends Monster {
|
|||||||
public void moveTo(Position position) {
|
public void moveTo(Position position) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enforceHealthMaximum() {
|
||||||
|
if (health > MAX_HEALTH) {
|
||||||
|
health = MAX_HEALTH;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
|
||||||
@@ -30,14 +31,13 @@ public class MonsterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void reaching_zero_health_triggers_death() {
|
void reaching_zero_health_triggers_death() {
|
||||||
defaultShade.kill();
|
defaultShade.takeDamage(Shade.MAX_HEALTH);
|
||||||
assertThat(false, equalTo(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.heal();
|
assertThrows(IllegalStateException.class, () -> defaultShade.heal());
|
||||||
assertThat(defaultShade.getHealth(), equalTo(0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user