Basic job implementation #5

Merged
erns6604 merged 10 commits from player into main 2025-10-17 10:06:38 +02:00
5 changed files with 23 additions and 13 deletions
Showing only changes of commit 00fb936641 - Show all commits

View File

@@ -1,21 +1,16 @@
public abstract class Character { public abstract class Character extends Entity {
protected String name; protected String name;
protected int health; protected int health;
protected int level; protected int level;
protected Position position;
public Character(String name) { public Character(String name) {
super(new Position(0, 0));
this.name = name; this.name = name;
this.health = 10; this.health = 10;
this.level = 1; this.level = 1;
} }
public Character(String name, int level) {
this.name = name;
this.level = level;
}
public void setHealth(int i) { public void setHealth(int i) {
this.health = i; this.health = i;
} }
@@ -24,5 +19,4 @@ public abstract class Character {
return health > 0; return health > 0;
} }
public abstract void spawn(int x, int y);
} }

14
src/main/java/Entity.java Normal file
View File

@@ -0,0 +1,14 @@
public class Entity {
private Position position;
public Entity(Position position) {
this.position = position;
}
public Position getPosition() {
return position;
}
public void setPosition(Position position) {
this.position = position;
}
}

View File

@@ -0,0 +1,3 @@
public interface Movable {
void move(Position position);
}

View File

@@ -1,4 +1,4 @@
public class Player extends Character { public class Player extends Character implements Movable {
public Player(String name) { public Player(String name) {
@@ -7,7 +7,7 @@ public class Player extends Character {
@Override @Override
public void spawn(int x, int y) { public void move(Position position) {
setPosition(position);
} }
} }

View File

@@ -18,8 +18,7 @@ class PlayerTest {
@Test @Test
public void can_change_position() { public void can_change_position() {
var p = defaultPlayer(); var p = defaultPlayer();
assertEquals(new Position(0,0), p.getPosition()); p.move(new Position(1,1));
p.moveTo(new Position(1,1));
assertEquals(new Position(1,1), p.getPosition()); assertEquals(new Position(1,1), p.getPosition());
} }