diff --git a/cicaprojekt/Box.java b/cicaprojekt/Box.java index e399c56..8789f9f 100644 --- a/cicaprojekt/Box.java +++ b/cicaprojekt/Box.java @@ -1,6 +1,6 @@ package cicaprojekt; -public class Box implements cicaprojekt.Pickable, cicaprojekt.Destroyable +public class Box implements Pickable, Destroyable { private int weight = 5; diff --git a/cicaprojekt/Dungeon.java b/cicaprojekt/Dungeon.java index dd890e7..79a98ea 100644 --- a/cicaprojekt/Dungeon.java +++ b/cicaprojekt/Dungeon.java @@ -36,13 +36,13 @@ public class Dungeon { case 'Z': Field zpmfield = new Field(); - zpmfield.setItemOnTile(new ZPM()); + zpmfield.setZPMOnTile(new ZPM()); dungeon[y][x] = zpmfield; break; case 'B': Field boxfield = new Field(); - boxfield.setItemOnTile(new Box()); + boxfield.putABox(new Box()); dungeon[y][x] = boxfield; break; diff --git a/cicaprojekt/Field.java b/cicaprojekt/Field.java index 75dfaf5..69161c9 100644 --- a/cicaprojekt/Field.java +++ b/cicaprojekt/Field.java @@ -5,27 +5,13 @@ import java.util.Map; public class Field extends cicaprojekt.Tile { - public static Map testAdjacentTile = new HashMap(); - public static Field testField = new Field(); - private static boolean testAdjTileSet = false; private static int recursionLimit = 0; public Field() { - setItemOnTile(new Box()); - adjacentTile = testAdjacentTile; - setTestAdjacentTile(); + super(); } - private void setTestAdjacentTile() { - if(!testAdjTileSet) { - testAdjacentTile.put(Direction.NORTH, Field.testField); - testAdjacentTile.put(Direction.EAST, Field.testField); - testAdjacentTile.put(Direction.SOUTH, Field.testField); - testAdjacentTile.put(Direction.WEST, Field.testField); - testAdjTileSet = true; - } - } @Override public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { @@ -34,9 +20,15 @@ public class Field extends cicaprojekt.Tile adjacentTile.get(direction).spawnStargate(stargate, direction); } - public void onEntry() { + public void onEntry(PlayerBase playerBase) { + if(boxStack.size() > 0) + return; + playerBase.setCurrentTile(this); + if(zpmOnTile != null) + playerBase.pickZPM(this); } - public void onExit() { + public void onExit(PlayerBase playerBase) { + return; } } diff --git a/cicaprojekt/Gap.java b/cicaprojekt/Gap.java index d939ebd..a07d80a 100644 --- a/cicaprojekt/Gap.java +++ b/cicaprojekt/Gap.java @@ -2,15 +2,25 @@ package cicaprojekt; public class Gap extends cicaprojekt.Tile { + public Gap(){ + super(); + } + @Override public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { adjacentTile.get(direction).spawnStargate(stargate, direction); } - public void onEntry() { - this.removeItemFromTile().destroy(); + public void onEntry(PlayerBase playerBase) { + playerBase.destroy(); } - public void onExit() { + public void onExit(PlayerBase playerBase) throws IllegalStateException { + throw new IllegalStateException("Hiba! A szakadékból nem jut ki semmi!"); + } + + @Override + public void putABox(Box box) { + box.destroy(); } } diff --git a/cicaprojekt/Gate.java b/cicaprojekt/Gate.java index 009ee67..e64ecdd 100644 --- a/cicaprojekt/Gate.java +++ b/cicaprojekt/Gate.java @@ -1,18 +1,29 @@ package cicaprojekt; -public class Gate extends cicaprojekt.Tile +public class Gate extends Tile { private boolean open = false; - - public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { + public Gate(){ + super(); + } + + public void spawnStargate(Stargate stargate, Direction direction) { if(this.open) adjacentTile.get(direction).spawnStargate(stargate, direction); } - public void onEntry() { + public void onEntry(PlayerBase playerBase) { + if(open){ + playerBase.setCurrentTile(this); + } + else + return; } - public void onExit() { + public void onExit(PlayerBase playerBase) throws IllegalStateException { + if(!open){ + throw new IllegalStateException("Hiba! Te hogy kerültél a csukott ajtóba?"); + } } public boolean isOpen() { diff --git a/cicaprojekt/Player.java b/cicaprojekt/Player.java index b266db2..9c249f1 100644 --- a/cicaprojekt/Player.java +++ b/cicaprojekt/Player.java @@ -1,5 +1,6 @@ package cicaprojekt; +import java.util.ArrayList; import java.util.List; public class Player extends PlayerBase{ @@ -8,20 +9,27 @@ public class Player extends PlayerBase{ public Player(Tile startTile, Direction startDirection){ + zpmContainer = new ArrayList<>(); currentTile = startTile; facingDirection = startDirection; /* Be lehetne állítani egy defaultot is, nem tudom, mennyire kéne */ } public void boxLift() { - boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).removeItemFromTile(); + boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).getABox(); } public void boxDrop() { - currentTile.getAdjacentTile(facingDirection).setItemOnTile(boxLifted); + currentTile.getAdjacentTile(facingDirection).putABox(boxLifted); boxLifted = null; } - - public void shootStargate(Stargate stargate) { + + @Override + public void pickZPM(Tile tile) + { + zpmContainer.add(tile.getZPMFromTile()); + } + + public void shootStargate(Stargate stargate) { this.currentTile.getAdjacentTile(facingDirection).spawnStargate(stargate, facingDirection); } } diff --git a/cicaprojekt/PlayerBase.java b/cicaprojekt/PlayerBase.java index e2c3825..29c2f5c 100644 --- a/cicaprojekt/PlayerBase.java +++ b/cicaprojekt/PlayerBase.java @@ -6,8 +6,7 @@ public class PlayerBase implements Destroyable{ protected Direction facingDirection; - public void destroy() { - } + public void destroy() {} public Tile getCurrentTile() { return currentTile; @@ -20,10 +19,12 @@ public class PlayerBase implements Destroyable{ public void move(Direction direction) { this.setFacingDirection(direction); Tile tile = this.getCurrentTile().getAdjacentTile(direction); - tile.onEntry(); + tile.onEntry(this); setCurrentTile(tile); } + public void pickZPM(Tile tile) { /* PlayerBase does not collect ZPM modules */ } + public void rotateLeft() { switch (facingDirection) { case NORTH: diff --git a/cicaprojekt/Scale.java b/cicaprojekt/Scale.java index 0dbb4cf..1d3fc49 100644 --- a/cicaprojekt/Scale.java +++ b/cicaprojekt/Scale.java @@ -4,7 +4,6 @@ import java.util.Stack; public class Scale extends Field { private Gate gateConnected; - private Stack itemsOnTile; private int threshold; private int weight; @@ -12,32 +11,38 @@ public class Scale extends Field { public Scale(Gate gate, int threshold){ gateConnected = gate; this.threshold = threshold; - itemsOnTile = new Stack(); + boxStack = new Stack(); } - public void onEntry() { + @Override + public void onEntry(PlayerBase playerBase) { gateConnected.setOpen(true); } - public void onExit() { + @Override + public void onExit(PlayerBase playerBase) { gateConnected.setOpen(false); } @Override - public Pickable removeItemFromTile() { - weight -= itemsOnTile.peek().weight(); + public Box getABox() { + if(boxStack.isEmpty()) + return null; + weight -= boxStack.peek().weight(); stackChanged(); - return itemsOnTile.pop(); + return boxStack.pop(); } @Override - public void setItemOnTile(Pickable item) { - itemsOnTile.push(item); - weight += item.weight(); + public void putABox(Box box) { + if(box == null) + return; + boxStack.push(box); + weight += box.weight(); stackChanged(); } - public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { + public void spawnStargate(Stargate stargate, Direction direction) { adjacentTile.get(direction).spawnStargate(stargate, direction); } diff --git a/cicaprojekt/Stargate.java b/cicaprojekt/Stargate.java index f7e7bbd..1bb37d0 100644 --- a/cicaprojekt/Stargate.java +++ b/cicaprojekt/Stargate.java @@ -2,24 +2,32 @@ package cicaprojekt; public class Stargate { private boolean isSpawned; - + public static final Stargate yellowStargate = new Stargate(); public static final Stargate blueStargate = new Stargate(); + public static final Stargate redStargate = new Stargate(); + public static final Stargate greenStargate = new Stargate(); public /*final*/ Stargate other; //TODO find better ways to do this - private cicaprojekt.Wall currentWall; + private Wall currentWall; + private Stargate() { + isSpawned = false; + } + public static void init() { yellowStargate.other = blueStargate; blueStargate.other = yellowStargate; + redStargate.other = greenStargate; + greenStargate.other = redStargate; } - public cicaprojekt.Wall getCurrentWall() { + public Wall getCurrentWall() { return currentWall; } - public void setCurrentWall(cicaprojekt.Wall wall) { + public void setCurrentWall(Wall wall) { currentWall = wall; } diff --git a/cicaprojekt/Tile.java b/cicaprojekt/Tile.java index 701a630..d8da251 100644 --- a/cicaprojekt/Tile.java +++ b/cicaprojekt/Tile.java @@ -2,20 +2,16 @@ package cicaprojekt; import java.util.HashMap; import java.util.Map; +import java.util.Stack; public abstract class Tile { protected Map adjacentTile; - private Pickable itemOnTile; + protected ZPM zpmOnTile; + protected Stack boxStack; public Tile(){ adjacentTile = new HashMap(); - - adjacentTile.put(Direction.NORTH, Field.testField); - adjacentTile.put(Direction.EAST, Field.testField); - adjacentTile.put(Direction.SOUTH, Field.testField); - adjacentTile.put(Direction.WEST, Field.testField); - itemOnTile = new Box(); } public Tile getAdjacentTile(Direction direction) { @@ -23,20 +19,34 @@ public abstract class Tile { } public void setAdajacentTile(Tile newTile, Direction direction) { + adjacentTile.put(direction, newTile); } public abstract void spawnStargate(Stargate stargate, Direction direction); - public abstract void onEntry(); + public abstract void onEntry(PlayerBase playerBase); - public abstract void onExit(); + public abstract void onExit(PlayerBase playerBase); - public Pickable removeItemFromTile() { - Pickable item = itemOnTile; - return item; + public void setZPMOnTile(ZPM zpm) { + zpmOnTile = zpm; } - public void setItemOnTile(Pickable item) { - itemOnTile = item; + public ZPM getZPMFromTile() { + ZPM zpm = zpmOnTile; + zpmOnTile = null; + return zpm; + } + + public void putABox(Box box) { + if(box == null) + return; + boxStack.push(box); + } + + public Box getABox(){ + if(boxStack.isEmpty()) + return null; + return boxStack.pop(); } } diff --git a/cicaprojekt/Wall.java b/cicaprojekt/Wall.java index 9d1cc89..9dd4949 100644 --- a/cicaprojekt/Wall.java +++ b/cicaprojekt/Wall.java @@ -3,6 +3,9 @@ package cicaprojekt; public class Wall extends Tile { private Stargate sg; + public Wall(){ + super(); + } public void spawnStargate(Stargate stargate, Direction direction) { if(sg == null) @@ -11,13 +14,20 @@ public class Wall extends Tile { return; } - public void clearStargate(){ - sg = null; + public void clearStargate() { + sg = null; } - public void onEntry() { + public void onEntry(PlayerBase playerBase) { + if(sg == null) { + return; + } + else { + sg.teleport(playerBase.facingDirection); + } } - public void onExit() { + public void onExit(PlayerBase playerBase) throws IllegalStateException { + throw new IllegalStateException("Hiba! Te hogy kerültél a falba?"); } } diff --git a/exampledungeon.dungeon b/exampledungeon.dungeon index 81e7b90..6c33bed 100644 --- a/exampledungeon.dungeon +++ b/exampledungeon.dungeon @@ -5,3 +5,5 @@ W O B S W W W G W W W F Z F W W W W W W + +1-3-2-2-5