Job + Spell merge #9

Merged
erns6604 merged 23 commits from Job into main 2025-10-27 12:18:22 +01:00
5 changed files with 33 additions and 9 deletions
Showing only changes of commit 33a2132e07 - Show all commits

View File

@@ -3,6 +3,7 @@ package Entity;
import Action.Action; import Action.Action;
import Action.Actor; import Action.Actor;
import Combat.HasHealth; import Combat.HasHealth;
import Inventory.Inventory;
import Job.Job; import Job.Job;
import Job.HasJob; import Job.HasJob;
import Inventory.HasInventory; import Inventory.HasInventory;
@@ -14,7 +15,7 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasJ
protected int health; protected int health;
protected Job job; protected Job job;
protected Position position; protected Position position;
protected List<String> items = new LinkedList<>(); protected Inventory inventory= new Inventory();
public Player(String name, Job job) { public Player(String name, Job job) {
super(name); super(name);
this.job = job; this.job = job;
@@ -45,13 +46,13 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasJ
this.job = job; this.job = job;
} }
public List<String> getInventory() { public Inventory getInventory() {
return items; return inventory;
} }
@Override @Override
public void performAction(Action action) { public void performAction(Action action) {
action.exectue(this); action.execute(this);
} }
@Override @Override

View File

@@ -3,5 +3,5 @@ package Inventory;
import java.util.List; import java.util.List;
public interface HasInventory { public interface HasInventory {
List<String> getInventory(); Inventory getInventory();
} }

View File

@@ -0,0 +1,24 @@
package Inventory;
import java.util.ArrayList;
import java.util.List;
public class Inventory {
List<String> items;
public Inventory() {
items = new ArrayList<>();
}
List<String> getItems() {
return items;
}
public void addItem(String item) {
items.add(item);
}
public boolean containsItem(String item) {
return items.contains(item);
}
}

View File

@@ -11,7 +11,7 @@ public class Miner extends Job {
public void dig(Actor actor) { public void dig(Actor actor) {
if (actor instanceof HasInventory a) { if (actor instanceof HasInventory a) {
a.getInventory().add("Stone"); a.getInventory().addItem("Stone");
} }
} }

View File

@@ -38,9 +38,8 @@ class PlayerTest {
@Test @Test
void miner_can_dig() { void miner_can_dig() {
var p = new Player("John"); var p = new Player("John");
var job = new Miner(); p.learnJob(new Miner());
p.learnJob(job);
p.performAction(new DigAction()); p.performAction(new DigAction());
assertTrue(p.getInventory().contains("Stone")); assertTrue(p.getInventory().containsItem("Stone"));
} }
} }