cicaprojekt/cicaprojekt/PlayerBase.java

98 lines
2.5 KiB
Java
Raw Normal View History

package cicaprojekt;
2016-04-24 21:01:34 +00:00
public class PlayerBase implements Destroyable {
protected Tile currentTile;
protected Direction facingDirection;
2016-04-25 11:56:41 +00:00
protected String name;
protected boolean destroyed;
2016-04-25 11:56:41 +00:00
public PlayerBase(String name, Tile startTile, Direction startDirection) {
this.name = name;
currentTile = startTile;
facingDirection = startDirection;
destroyed = false;
2016-04-25 11:56:41 +00:00
}
2016-04-25 17:14:54 +00:00
@Override
public String toString() {
return String.format("%s: %s", name, currentTile);
}
2016-05-14 11:47:14 +00:00
@Override
2016-04-24 21:01:34 +00:00
public void destroy() {
destroyed = true;
Game.instance.playerBaseDestroyed(this);
2016-04-24 21:01:34 +00:00
}
2016-04-24 21:01:34 +00:00
public Tile getCurrentTile() {
return currentTile;
}
2016-04-24 21:01:34 +00:00
public void setCurrentTile(Tile newCurrentTile) {
currentTile = newCurrentTile;
}
2016-04-24 21:01:34 +00:00
public void move(Direction direction) {
2016-05-13 20:10:29 +00:00
if(!isDestroyed()) {
this.setFacingDirection(direction);
Tile adjtile = this.getCurrentTile().getAdjacentTile(direction);
if (adjtile != null) {
if (adjtile.isSteppable()) {
currentTile.onExit(this);
setCurrentTile(adjtile);
adjtile.onEntry(this);
}
}
2016-05-13 15:23:37 +00:00
}
2016-04-24 21:01:34 +00:00
}
public void pickZPM(Tile tile) { /* PlayerBase does not collect ZPM modules */ }
2016-04-24 21:01:34 +00:00
public void rotateLeft() {
switch (facingDirection) {
case NORTH:
facingDirection = Direction.WEST;
break;
case WEST:
facingDirection = Direction.SOUTH;
break;
case SOUTH:
facingDirection = Direction.EAST;
break;
case EAST:
facingDirection = Direction.NORTH;
break;
}
}
2016-04-24 21:01:34 +00:00
public void rotateRight() {
switch (facingDirection) {
case NORTH:
facingDirection = Direction.EAST;
break;
case EAST:
facingDirection = Direction.SOUTH;
break;
case SOUTH:
facingDirection = Direction.WEST;
break;
case WEST:
facingDirection = Direction.NORTH;
break;
}
}
2016-04-24 21:01:34 +00:00
public Direction getFacingDirection() {
return facingDirection;
}
2016-04-24 21:01:34 +00:00
public void setFacingDirection(Direction direction) {
facingDirection = direction;
}
public boolean isDestroyed(){
return destroyed;
}
}