Job + Spell merge #9
@@ -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
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
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) {
|
public void dig(Actor actor) {
|
||||||
if (actor instanceof HasInventory a) {
|
if (actor instanceof HasInventory a) {
|
||||||
a.getInventory().add("Stone");
|
a.getInventory().addItem("Stone");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user