Basic job implementation #5

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

View File

@@ -0,0 +1,5 @@
package Action;
public abstract class Action {
public static Dig Dig = new Dig();
}

View File

@@ -0,0 +1,5 @@
package Action;
public class Dig extends Action {
}

View File

@@ -1,5 +1,21 @@
package Job;
public interface Job {
void performJobAction();
public abstract class Job {
private int level;
abstract void performJobAction();
Job() {
this.level = 1;
}
Job(int level) {
this.level = level;
}
public double getLevel() {
return level;
};
public void levelUp() {
level++;
}
}

View File

@@ -2,7 +2,7 @@ package Job;
import java.util.Objects;
public class Miner implements Job {
public class Miner extends Job {
private final String jobName = "Miner";
public Miner() {}

View File

@@ -1,7 +1,13 @@
import Action.Dig;
import Job.Job;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public class Player extends Character implements Movable {
protected Job job;
protected List<String> items = new LinkedList<>();
public Player(String name, Job job) {
super(name);
this.job = job;
@@ -23,4 +29,12 @@ public class Player extends Character implements Movable {
public Job getJob() {
return job;
}
public void performAction(Dig dig) {
items.add("Stone");
}
public List<String> getInventory() {
return items;
}
}

View File

@@ -0,0 +1,29 @@
import Action.Action;
import Job.Miner;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MinerTest {
@Test
void miner_can_dig() {
var p = new Player("Steve");
var job = new Miner();
p.learnJob(job);
p.performAction(Action.Dig);
assertTrue(p.getInventory().contains("Stone"));
}
@Test
void miner_can_level_up() {
var p = new Player("Steve");
var job = new Miner();
assertEquals(1, job.getLevel());
job.levelUp();
assertEquals(2, job.getLevel());
}
}