Job + Spell merge #9
19
src/main/java/Action/learnSpellAction.java
Normal file
19
src/main/java/Action/learnSpellAction.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package Action;
|
||||||
|
|
||||||
|
import Job.HasJob;
|
||||||
|
import Job.Wizard;
|
||||||
|
|
||||||
|
public class learnSpellAction implements Action {
|
||||||
|
@Override
|
||||||
|
public void exectue(Actor actor) {
|
||||||
|
Wizard wizard = requireWizard(actor);
|
||||||
|
wizard.learnSpell(actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Wizard requireWizard(Actor actor) {
|
||||||
|
if (actor instanceof HasJob hasJob && hasJob.getJob() instanceof Wizard wizard) {
|
||||||
|
return wizard;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException(actor + " cannot perform this action without being a Wizard!");
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/main/java/Character/HasSpellBook.java
Normal file
7
src/main/java/Character/HasSpellBook.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package Character;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface HasSpellBook {
|
||||||
|
List<String> getSpellBook();
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import Combat.HasHealth;
|
|||||||
import Job.Job;
|
import Job.Job;
|
||||||
import Job.HasJob;
|
import Job.HasJob;
|
||||||
import Inventory.HasInventory;
|
import Inventory.HasInventory;
|
||||||
|
import Inventory.HasSpellBook;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -15,6 +16,7 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasJ
|
|||||||
protected Job job;
|
protected Job job;
|
||||||
protected Position position;
|
protected Position position;
|
||||||
protected List<String> items = new LinkedList<>();
|
protected List<String> items = new LinkedList<>();
|
||||||
|
protected List<String> spells = new LinkedList<>();
|
||||||
public Player(String name, Job job) {
|
public Player(String name, Job job) {
|
||||||
super(name);
|
super(name);
|
||||||
this.job = job;
|
this.job = job;
|
||||||
@@ -49,6 +51,8 @@ public class Player extends Entity implements Movable, Actor, HasInventory, HasJ
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getSpellBook() {return spells;}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performAction(Action action) {
|
public void performAction(Action action) {
|
||||||
action.exectue(this);
|
action.exectue(this);
|
||||||
|
|||||||
7
src/main/java/Inventory/HasSpellBook.java
Normal file
7
src/main/java/Inventory/HasSpellBook.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package Inventory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface HasSpellBook {
|
||||||
|
List<String> getSpellBook();
|
||||||
|
}
|
||||||
24
src/main/java/Job/Wizard.java
Normal file
24
src/main/java/Job/Wizard.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package Job;
|
||||||
|
|
||||||
|
import Action.Actor;
|
||||||
|
import Character.HasSpellBook;
|
||||||
|
|
||||||
|
public class Wizard extends Job {
|
||||||
|
public Wizard() {super("Wizard");}
|
||||||
|
|
||||||
|
public void learnSpell(Actor actor) {
|
||||||
|
if(actor instanceof HasSpellBook a ) {
|
||||||
|
a.getSpellBook().add("Fireball");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getExperience() {
|
||||||
|
return experience;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gainExperience(int exp) {
|
||||||
|
experience += exp;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import Action.DigAction;
|
import Action.DigAction;
|
||||||
|
import Action.learnSpellAction;
|
||||||
import Entity.Position;
|
import Entity.Position;
|
||||||
import Job.Miner;
|
import Job.Miner;
|
||||||
import Entity.Player;
|
import Entity.Player;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import Job.Wizard;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|||||||
7
src/test/java/WizardTest.java
Normal file
7
src/test/java/WizardTest.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import Job.Wizard;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class WizardTest {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user