Job + Spell merge #9

Merged
erns6604 merged 23 commits from Job into main 2025-10-27 12:18:22 +01:00
7 changed files with 20 additions and 26 deletions
Showing only changes of commit 4e0d180903 - Show all commits

View File

@@ -20,10 +20,9 @@
<version>5.8.1</version> <version>5.8.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId> <artifactId>hamcrest-core</artifactId>
<version>2.2</version> <version>2.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@@ -4,16 +4,16 @@ import Job.HasJob;
import Job.Wizard; import Job.Wizard;
public class CastAction implements Action { public class CastAction implements Action {
@Override
public void exectue(Actor actor) {
Wizard wizard = requireWizard(actor);
wizard.castSpell(actor);
}
private Wizard requireWizard(Actor actor) { private Wizard requireWizard(Actor actor) {
if (actor instanceof HasJob hasJob && hasJob.getJob() instanceof Wizard wizard) { if (actor instanceof HasJob hasJob && hasJob.getJob() instanceof Wizard wizard) {
return wizard; return wizard;
} }
throw new IllegalStateException(actor + " cannot perform this action without being a Wizard!"); throw new IllegalStateException(actor + " cannot perform this action without being a Wizard!");
} }
@Override
public void execute(Actor player) {
var wizard = requireWizard(player);
wizard.castSpell(player);
}
} }

View File

@@ -5,7 +5,7 @@ import Job.Wizard;
public class LearnSpellAction implements Action { public class LearnSpellAction implements Action {
@Override @Override
public void exectue(Actor actor) { public void execute(Actor actor) {
Wizard wizard = requireWizard(actor); Wizard wizard = requireWizard(actor);
wizard.learnSpell(actor); wizard.learnSpell(actor);
} }

View File

@@ -20,8 +20,6 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasS
protected Job job; protected Job job;
protected Position position = new Position(0,0); protected Position position = new Position(0,0);
protected Inventory inventory= new Inventory(); protected Inventory inventory= new Inventory();
protected Position position;
protected List<String> items = new LinkedList<>();
protected List<Spell> spells = new LinkedList<>(); protected List<Spell> spells = new LinkedList<>();
public Player(String name, Job job) { public Player(String name, Job job) {
super(name); super(name);
@@ -42,7 +40,7 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasS
@Override @Override
public boolean canMoveTo(Position position) { public boolean canMoveTo(Position position) {
return false; return true;
} }
public Job getJob() { public Job getJob() {
return job; return job;

View File

@@ -1,23 +1,15 @@
import Action.Actor;
import Combat.HasMana;
import Combat.OffensiveDamageSpell; import Combat.OffensiveDamageSpell;
import Combat.Spell;
import Entity.Entity;
import Entity.Player; import Entity.Player;
import Inventory.HasSpellBook;
import Job.Wizard; import Job.Wizard;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.*;
public class InterestingTests { public class InterestingTests {
@@ -67,7 +59,7 @@ public class InterestingTests {
wizard.castSpell(player); wizard.castSpell(player);
assertThat(player.getMana(),is(initialMana)); assertThat(player.getMana(), is(initialMana));
assertThat(player.getHealth(),is(initialHealth)); assertThat(player.getHealth(),is(initialHealth));
} }
} }

View File

@@ -17,7 +17,7 @@ public class MagicSystemTest {
CastAction action = new CastAction(); CastAction action = new CastAction();
IllegalStateException exception = assertThrows( IllegalStateException exception = assertThrows(
IllegalStateException.class, IllegalStateException.class,
() -> action.exectue(p) () -> action.execute(p)
); );
assertTrue(exception.getMessage().contains("cannot perform this action without being a Wizard")); assertTrue(exception.getMessage().contains("cannot perform this action without being a Wizard"));
@@ -28,7 +28,7 @@ public class MagicSystemTest {
LearnSpellAction action = new LearnSpellAction(); LearnSpellAction action = new LearnSpellAction();
IllegalStateException exception = assertThrows( IllegalStateException exception = assertThrows(
IllegalStateException.class, IllegalStateException.class,
() -> action.exectue(p) () -> action.execute(p)
); );
assertTrue(exception.getMessage().contains("cannot perform this action without being a Wizard")); assertTrue(exception.getMessage().contains("cannot perform this action without being a Wizard"));
} }

View File

@@ -34,6 +34,11 @@ public class MinerTest {
assertEquals(10, job.getExperience()); assertEquals(10, job.getExperience());
} }
@Test
void dig_on_ice_require_ice_pick() {
}
} }