Basic job implementation #5
26
src/main/java/Job/Job.java
Normal file
26
src/main/java/Job/Job.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package Job;
|
||||||
|
|
||||||
|
public class Job {
|
||||||
|
protected String name;
|
||||||
|
public Job(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Job Miner() {
|
||||||
|
return new Job("Miner");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Job job = (Job) o;
|
||||||
|
return name.equals(job.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return name.hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
|
import Job.Job;
|
||||||
|
|
||||||
public class Player extends Character implements Movable {
|
public class Player extends Character implements Movable {
|
||||||
|
|
||||||
|
protected Job job;
|
||||||
|
public Player(String name, Job job) {
|
||||||
|
super(name);
|
||||||
|
this.job = job;
|
||||||
|
}
|
||||||
|
|
||||||
public Player(String name) {
|
public Player(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
@@ -7,7 +14,15 @@ public class Player extends Character implements Movable {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void move(Position position) {
|
public void moveTo(Position position) {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void learnJob(Job job) {
|
||||||
|
this.job = job;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Job getJob() {
|
||||||
|
return job;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import Job.Job;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -22,4 +23,15 @@ class PlayerTest {
|
|||||||
assertEquals(new Position(1,1), p.getPosition());
|
assertEquals(new Position(1,1), p.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void can_change_job() {
|
||||||
|
var p = defaultPlayer();
|
||||||
|
var job = Job.Miner();
|
||||||
|
assertNull(p.getJob());
|
||||||
|
p.learnJob(job);
|
||||||
|
assertEquals(Job.Miner(), p.getJob());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user