Refactored ONeill into PlayerBase and Player

Change was needed because of updated specification.
This commit is contained in:
Bokros Bálint 2016-04-19 11:46:06 +02:00
parent db54dcdd1d
commit f45ed417ae
5 changed files with 142 additions and 134 deletions

View File

@ -1,7 +1,7 @@
package cicaprojekt;
public class Game {
private cicaprojekt.ONeill oneill;
private Player oneill;
private Dungeon dungeon;
private FlowOfTime flowoftime;

View File

@ -30,7 +30,7 @@ public class Menu {
System.out.println("6. Csillagkapu lövés");
System.out.println("X. Kilépés");
ONeill oNeill = new ONeill(new Field(), Direction.NORTH);
Player oNeill = new Player(new Field(), Direction.NORTH);
Scanner sc = new Scanner(System.in);

View File

@ -1,132 +0,0 @@
package cicaprojekt;
import java.util.List;
public class ONeill implements Destroyable{
private Game game;
private List<ZPM> zpmContainer;
private cicaprojekt.Tile currentTile;
private Direction facingDirection;
private Box boxLifted;
public ONeill(cicaprojekt.Tile startTile, Direction startDirection){
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.ONeill(" + startTile + startDirection + ")");
currentTile = startTile;
facingDirection = startDirection; /* Be lehetne állítani egy defaultot is, nem tudom, mennyire kéne */
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.ONeill()");
Menu.removeTab();
}
public void destroy() {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.destroy()");
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.destroy()");
Menu.removeTab();
}
public cicaprojekt.Tile getCurrentTile() {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.getCurrentTile()");
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.getCurrentTile()");
Menu.removeTab();
return currentTile;
}
public void setCurrentTile(cicaprojekt.Tile newCurrentTile) {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.setCurrentTile()");
currentTile = newCurrentTile;
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.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 boxLift() {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.boxLift()");
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.boxLift()");
Menu.removeTab();
boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).removeItemFromTile();
}
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 void boxDrop() {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.boxDrop()");
currentTile.getAdjacentTile(facingDirection).setItemOnTile(boxLifted);
boxLifted = null;
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.boxDrop()");
Menu.removeTab();
}
public Direction getFacingDirection() {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.getFacingDirection()");
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.getFacingDirection()");
Menu.removeTab();
return facingDirection;
}
public void setFacingDirection(Direction direction) {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.setFacingDirection(" + direction.name() + ")");
facingDirection = direction;
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.setFacingDirection()");
Menu.removeTab();
}
public void shootStargate(Stargate stargate) {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.shootStargate(stargate)");
this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection);
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "ONeill.shootStargate()");
Menu.removeTab();
}
}

47
cicaprojekt/Player.java Normal file
View File

@ -0,0 +1,47 @@
package cicaprojekt;
import java.util.List;
public class Player extends PlayerBase{
private List<ZPM> zpmContainer;
private Box boxLifted;
public Player(Tile startTile, Direction startDirection){
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.Player(" + startTile + startDirection + ")");
currentTile = startTile;
facingDirection = startDirection; /* Be lehetne állítani egy defaultot is, nem tudom, mennyire kéne */
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.Player()");
Menu.removeTab();
}
public void boxLift() {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.boxLift()");
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.boxLift()");
Menu.removeTab();
boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).removeItemFromTile();
}
public void boxDrop() {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.boxDrop()");
currentTile.getAdjacentTile(facingDirection).setItemOnTile(boxLifted);
boxLifted = null;
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.boxDrop()");
Menu.removeTab();
}
public void shootStargate(Stargate stargate) {
Menu.addTab();
System.out.println(">" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.shootStargate(stargate)");
this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection);
System.out.println("<" + "[" + ":" + this.getClass().getSimpleName() + "]" + Menu.tabulator + "Player.shootStargate()");
Menu.removeTab();
}
}

View 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();
}
}