2016-04-19 09:46:06 +00:00
|
|
|
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;
|
2016-04-25 22:44:47 +00:00
|
|
|
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;
|
2016-04-25 22:44:47 +00:00
|
|
|
destroyed = false;
|
2016-04-25 11:56:41 +00:00
|
|
|
}
|
2016-04-19 09:46:06 +00:00
|
|
|
|
2016-04-25 17:14:54 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return String.format("%s: %s", name, currentTile);
|
|
|
|
}
|
2016-04-23 15:15:19 +00:00
|
|
|
|
2016-05-14 11:47:14 +00:00
|
|
|
@Override
|
2016-04-24 21:01:34 +00:00
|
|
|
public void destroy() {
|
2016-04-25 22:44:47 +00:00
|
|
|
destroyed = true;
|
2016-05-14 08:44:36 +00:00
|
|
|
Game.instance.playerBaseDestroyed(this);
|
2016-04-24 21:01:34 +00:00
|
|
|
}
|
2016-04-19 09:46:06 +00:00
|
|
|
|
2016-04-24 21:01:34 +00:00
|
|
|
public Tile getCurrentTile() {
|
|
|
|
return currentTile;
|
|
|
|
}
|
2016-04-19 09:46:06 +00:00
|
|
|
|
2016-04-24 21:01:34 +00:00
|
|
|
public void setCurrentTile(Tile newCurrentTile) {
|
|
|
|
currentTile = newCurrentTile;
|
|
|
|
}
|
2016-04-19 09:46:06 +00:00
|
|
|
|
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:59:14 +00:00
|
|
|
}
|
2016-05-13 15:23:37 +00:00
|
|
|
}
|
2016-04-24 21:01:34 +00:00
|
|
|
}
|
2016-04-19 09:46:06 +00:00
|
|
|
|
2016-04-24 20:48:17 +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-19 09:46:06 +00:00
|
|
|
|
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-19 09:46:06 +00:00
|
|
|
|
2016-04-24 21:01:34 +00:00
|
|
|
public Direction getFacingDirection() {
|
|
|
|
return facingDirection;
|
|
|
|
}
|
2016-04-19 09:46:06 +00:00
|
|
|
|
2016-04-24 21:01:34 +00:00
|
|
|
public void setFacingDirection(Direction direction) {
|
|
|
|
facingDirection = direction;
|
|
|
|
}
|
2016-04-25 22:44:47 +00:00
|
|
|
|
|
|
|
public boolean isDestroyed(){
|
|
|
|
return destroyed;
|
|
|
|
}
|
2016-04-19 09:46:06 +00:00
|
|
|
}
|