Basic job implementation #5
@@ -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
14
src/main/java/Entity.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/main/java/Movable.java
Normal file
3
src/main/java/Movable.java
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
public interface Movable {
|
||||||
|
void moveTo(Position position);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ 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.moveTo(new Position(1,1));
|
p.moveTo(new Position(1,1));
|
||||||
assertEquals(new Position(1,1), p.getPosition());
|
assertEquals(new Position(1,1), p.getPosition());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user