Job + Spell merge #9
@@ -3,6 +3,7 @@ package Entity;
|
||||
import Action.Action;
|
||||
import Action.Actor;
|
||||
import Combat.HasHealth;
|
||||
import Inventory.Inventory;
|
||||
import Job.Job;
|
||||
import Job.HasJob;
|
||||
import Inventory.HasInventory;
|
||||
@@ -14,7 +15,7 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasJ
|
||||
protected int health;
|
||||
protected Job job;
|
||||
protected Position position;
|
||||
protected List<String> items = new LinkedList<>();
|
||||
protected Inventory inventory= new Inventory();
|
||||
public Player(String name, Job job) {
|
||||
super(name);
|
||||
this.job = job;
|
||||
@@ -45,13 +46,13 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasJ
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public List<String> getInventory() {
|
||||
return items;
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(Action action) {
|
||||
action.exectue(this);
|
||||
action.execute(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,5 +3,5 @@ package Inventory;
|
||||
import java.util.List;
|
||||
|
||||
public interface HasInventory {
|
||||
List<String> getInventory();
|
||||
Inventory getInventory();
|
||||
}
|
||||
|
||||
24
src/main/java/Inventory/Inventory.java
Normal file
24
src/main/java/Inventory/Inventory.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public class Miner extends Job {
|
||||
|
||||
public void dig(Actor actor) {
|
||||
if (actor instanceof HasInventory a) {
|
||||
a.getInventory().add("Stone");
|
||||
a.getInventory().addItem("Stone");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,8 @@ class PlayerTest {
|
||||
@Test
|
||||
void miner_can_dig() {
|
||||
var p = new Player("John");
|
||||
var job = new Miner();
|
||||
p.learnJob(job);
|
||||
p.learnJob(new Miner());
|
||||
p.performAction(new DigAction());
|
||||
assertTrue(p.getInventory().contains("Stone"));
|
||||
assertTrue(p.getInventory().containsItem("Stone"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user