From f45ed417ae30824daa11d19a7a1b6eb1ef614223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bokros=20B=C3=A1lint?= Date: Tue, 19 Apr 2016 11:46:06 +0200 Subject: [PATCH] Refactored ONeill into PlayerBase and Player Change was needed because of updated specification. --- cicaprojekt/Game.java | 2 +- cicaprojekt/Menu.java | 2 +- cicaprojekt/ONeill.java | 132 ------------------------------------ cicaprojekt/Player.java | 47 +++++++++++++ cicaprojekt/PlayerBase.java | 93 +++++++++++++++++++++++++ 5 files changed, 142 insertions(+), 134 deletions(-) delete mode 100644 cicaprojekt/ONeill.java create mode 100644 cicaprojekt/Player.java create mode 100644 cicaprojekt/PlayerBase.java diff --git a/cicaprojekt/Game.java b/cicaprojekt/Game.java index 5cc71d2..260f351 100644 --- a/cicaprojekt/Game.java +++ b/cicaprojekt/Game.java @@ -1,7 +1,7 @@ package cicaprojekt; public class Game { - private cicaprojekt.ONeill oneill; + private Player oneill; private Dungeon dungeon; private FlowOfTime flowoftime; diff --git a/cicaprojekt/Menu.java b/cicaprojekt/Menu.java index d0b94cf..b5a85da 100644 --- a/cicaprojekt/Menu.java +++ b/cicaprojekt/Menu.java @@ -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); diff --git a/cicaprojekt/ONeill.java b/cicaprojekt/ONeill.java deleted file mode 100644 index 50d4764..0000000 --- a/cicaprojekt/ONeill.java +++ /dev/null @@ -1,132 +0,0 @@ -package cicaprojekt; - -import java.util.List; - -public class ONeill implements Destroyable{ - private Game game; - private List 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(); - } -} diff --git a/cicaprojekt/Player.java b/cicaprojekt/Player.java new file mode 100644 index 0000000..6d42b9e --- /dev/null +++ b/cicaprojekt/Player.java @@ -0,0 +1,47 @@ +package cicaprojekt; + +import java.util.List; + +public class Player extends PlayerBase{ + private List 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(); + } +} diff --git a/cicaprojekt/PlayerBase.java b/cicaprojekt/PlayerBase.java new file mode 100644 index 0000000..f0167c7 --- /dev/null +++ b/cicaprojekt/PlayerBase.java @@ -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(); + } + +}