Refactored ONeill into PlayerBase and Player
Change was needed because of updated specification.
This commit is contained in:
93
cicaprojekt/PlayerBase.java
Normal file
93
cicaprojekt/PlayerBase.java
Normal file
@ -0,0 +1,93 @@
|
||||
package cicaprojekt;
|
||||
|
||||
|
||||
public class PlayerBase implements Destroyable{
|
||||
protected Game game;
|
||||
protected Tile currentTile;
|
||||
protected Direction facingDirection;
|
||||
|
||||
public void destroy() {
|
||||
Menu.addTab();
|
||||
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.destroy()");
|
||||
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.destroy()");
|
||||
Menu.removeTab();
|
||||
}
|
||||
|
||||
public Tile getCurrentTile() {
|
||||
Menu.addTab();
|
||||
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.getCurrentTile()");
|
||||
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.getCurrentTile()");
|
||||
Menu.removeTab();
|
||||
return currentTile;
|
||||
}
|
||||
|
||||
public void setCurrentTile(Tile newCurrentTile) {
|
||||
Menu.addTab();
|
||||
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.setCurrentTile()");
|
||||
currentTile = newCurrentTile;
|
||||
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.setCurrentTile()");
|
||||
Menu.removeTab();
|
||||
}
|
||||
|
||||
public void move(Direction direction) {
|
||||
Menu.addTab();
|
||||
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Oneill.move(" + direction.name() + ")");
|
||||
this.setFacingDirection(direction);
|
||||
Tile tile = this.getCurrentTile().getAdjacentTile(direction);
|
||||
tile.onEntry();
|
||||
setCurrentTile(tile);
|
||||
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Oneill.move()");
|
||||
Menu.removeTab();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public Direction getFacingDirection() {
|
||||
Menu.addTab();
|
||||
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.getFacingDirection()");
|
||||
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.getFacingDirection()");
|
||||
Menu.removeTab();
|
||||
return facingDirection;
|
||||
}
|
||||
|
||||
public void setFacingDirection(Direction direction) {
|
||||
Menu.addTab();
|
||||
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.setFacingDirection(" + direction.name() + ")");
|
||||
facingDirection = direction;
|
||||
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.setFacingDirection()");
|
||||
Menu.removeTab();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user