Basic job implementation #5

Merged
erns6604 merged 10 commits from player into main 2025-10-17 10:06:38 +02:00
3 changed files with 54 additions and 1 deletions
Showing only changes of commit c40b5a0c84 - Show all commits

View 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();
}
}

View File

@@ -1,5 +1,12 @@
import Job.Job;
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) {
super(name);
@@ -7,7 +14,15 @@ public class Player extends Character implements Movable {
@Override
public void move(Position position) {
public void moveTo(Position position) {
setPosition(position);
}
public void learnJob(Job job) {
this.job = job;
}
public Job getJob() {
return job;
}
}

View File

@@ -1,3 +1,4 @@
import Job.Job;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@@ -22,4 +23,15 @@ class PlayerTest {
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());
}
}