From 6b11456b7a862ac9792969f7c570e145b5e0415c Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 18:27:36 +0200 Subject: [PATCH 01/16] Abstract class finished Method-calling texts were removed and methods were implemented. --- cicaprojekt/Tile.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cicaprojekt/Tile.java b/cicaprojekt/Tile.java index 701a630..05732de 100644 --- a/cicaprojekt/Tile.java +++ b/cicaprojekt/Tile.java @@ -23,6 +23,7 @@ public abstract class Tile { } public void setAdajacentTile(Tile newTile, Direction direction) { + adjacentTile.put(direction, newTile); } public abstract void spawnStargate(Stargate stargate, Direction direction); @@ -33,10 +34,11 @@ public abstract class Tile { public Pickable removeItemFromTile() { Pickable item = itemOnTile; + itemOnTile = null; return item; } public void setItemOnTile(Pickable item) { - itemOnTile = item; + itemOnTile = item; } } From 64e6aec17600c0d7d1bff2157c6dd51846f3c0a7 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 18:36:11 +0200 Subject: [PATCH 02/16] Implemented onExit in Wall --- cicaprojekt/Wall.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cicaprojekt/Wall.java b/cicaprojekt/Wall.java index 9d1cc89..a6eed9e 100644 --- a/cicaprojekt/Wall.java +++ b/cicaprojekt/Wall.java @@ -11,13 +11,20 @@ public class Wall extends Tile { return; } - public void clearStargate(){ - sg = null; + public void clearStargate() { + sg = null; } public void onEntry() { + if(sg == null) { + + } + else { + + } } public void onExit() { + throw new IllegalStateException("Hiba! Te hogy kerültél a falba?"); } } From 73c42991eb10843a00e8a99d50048cffde8459b7 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 19:49:27 +0200 Subject: [PATCH 03/16] OnEntry/OnExit changed The argument of these methods were changed from void to PlayerBase playerBase. --- cicaprojekt/Tile.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cicaprojekt/Tile.java b/cicaprojekt/Tile.java index 05732de..8ba3c6d 100644 --- a/cicaprojekt/Tile.java +++ b/cicaprojekt/Tile.java @@ -28,9 +28,9 @@ public abstract class Tile { 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; From 708ad09c5eeb42feeb91f69c29ee29139d722b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bokros=20B=C3=A1lint?= Date: Sun, 24 Apr 2016 20:09:02 +0200 Subject: [PATCH 04/16] Cosmetic fixes in Stargate --- cicaprojekt/Stargate.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cicaprojekt/Stargate.java b/cicaprojekt/Stargate.java index f7e7bbd..5c3e578 100644 --- a/cicaprojekt/Stargate.java +++ b/cicaprojekt/Stargate.java @@ -7,7 +7,7 @@ public class Stargate { public static final Stargate blueStargate = new Stargate(); public /*final*/ Stargate other; //TODO find better ways to do this - private cicaprojekt.Wall currentWall; + private Wall currentWall; public static void init() { @@ -15,11 +15,11 @@ public class Stargate { blueStargate.other = yellowStargate; } - public cicaprojekt.Wall getCurrentWall() { + public Wall getCurrentWall() { return currentWall; } - public void setCurrentWall(cicaprojekt.Wall wall) { + public void setCurrentWall(Wall wall) { currentWall = wall; } From c6a0b984eb01c817328e47770f046ac257fb011d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bokros=20B=C3=A1lint?= Date: Sun, 24 Apr 2016 20:09:53 +0200 Subject: [PATCH 05/16] Added red and green Stargates --- cicaprojekt/Stargate.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cicaprojekt/Stargate.java b/cicaprojekt/Stargate.java index 5c3e578..c365dc7 100644 --- a/cicaprojekt/Stargate.java +++ b/cicaprojekt/Stargate.java @@ -2,9 +2,11 @@ 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 Wall currentWall; @@ -13,6 +15,8 @@ public class Stargate { public static void init() { yellowStargate.other = blueStargate; blueStargate.other = yellowStargate; + redStargate.other = greenStargate; + greenStargate.other = redStargate; } public Wall getCurrentWall() { From b32fec8c520cc02e7115e6dd6f276d34acc18642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bokros=20B=C3=A1lint?= Date: Sun, 24 Apr 2016 20:10:31 +0200 Subject: [PATCH 06/16] Stargate's isSpawned attribute is now properly initialized --- cicaprojekt/Stargate.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cicaprojekt/Stargate.java b/cicaprojekt/Stargate.java index c365dc7..1bb37d0 100644 --- a/cicaprojekt/Stargate.java +++ b/cicaprojekt/Stargate.java @@ -12,6 +12,10 @@ public class Stargate { private Wall currentWall; + private Stargate() { + isSpawned = false; + } + public static void init() { yellowStargate.other = blueStargate; blueStargate.other = yellowStargate; From 794378a9191bdc1443581615faf5ad308b0aaf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bokros=20B=C3=A1lint?= Date: Sun, 24 Apr 2016 20:21:01 +0200 Subject: [PATCH 07/16] Removed unneeded 'cicaprojekt.'-s from the project --- cicaprojekt/Box.java | 2 +- cicaprojekt/Field.java | 4 ++-- cicaprojekt/Gap.java | 4 ++-- cicaprojekt/Gate.java | 4 ++-- cicaprojekt/Scale.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) 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/Field.java b/cicaprojekt/Field.java index 75dfaf5..e10e5b4 100644 --- a/cicaprojekt/Field.java +++ b/cicaprojekt/Field.java @@ -3,7 +3,7 @@ package cicaprojekt; import java.util.HashMap; import java.util.Map; -public class Field extends cicaprojekt.Tile +public class Field extends Tile { public static Map testAdjacentTile = new HashMap(); public static Field testField = new Field(); @@ -28,7 +28,7 @@ public class Field extends cicaprojekt.Tile } @Override - public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { + public void spawnStargate(Stargate stargate, Direction direction) { if (recursionLimit++ >= 10) this.adjacentTile.put(direction, new Wall()); adjacentTile.get(direction).spawnStargate(stargate, direction); diff --git a/cicaprojekt/Gap.java b/cicaprojekt/Gap.java index d939ebd..fb1d807 100644 --- a/cicaprojekt/Gap.java +++ b/cicaprojekt/Gap.java @@ -1,9 +1,9 @@ package cicaprojekt; -public class Gap extends cicaprojekt.Tile +public class Gap extends Tile { @Override - 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/Gate.java b/cicaprojekt/Gate.java index 009ee67..e67e526 100644 --- a/cicaprojekt/Gate.java +++ b/cicaprojekt/Gate.java @@ -1,11 +1,11 @@ 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 void spawnStargate(Stargate stargate, Direction direction) { if(this.open) adjacentTile.get(direction).spawnStargate(stargate, direction); } diff --git a/cicaprojekt/Scale.java b/cicaprojekt/Scale.java index 0dbb4cf..591512f 100644 --- a/cicaprojekt/Scale.java +++ b/cicaprojekt/Scale.java @@ -37,7 +37,7 @@ public class Scale extends Field { stackChanged(); } - public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { + public void spawnStargate(Stargate stargate, Direction direction) { adjacentTile.get(direction).spawnStargate(stargate, direction); } From 4f81192938cb63559e2c47c96989dac93a056466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 24 Apr 2016 20:25:35 +0200 Subject: [PATCH 08/16] added scale-gate references to dungeon files and their parser --- cicaprojekt/Dungeon.java | 58 +++++++++++++++++++++++++++++++++------- exampledungeon.dungeon | 2 ++ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/cicaprojekt/Dungeon.java b/cicaprojekt/Dungeon.java index dd890e7..2bc7815 100644 --- a/cicaprojekt/Dungeon.java +++ b/cicaprojekt/Dungeon.java @@ -1,9 +1,35 @@ package cicaprojekt; import java.io.*; +import java.util.HashMap; +import java.util.Map; public class Dungeon { - cicaprojekt.Tile buildDungeon(File input) throws IOException + /* NOTE: this function assumes that the parameter input is a well-formatted dungeon file. + * Such file looks like as follows: + * + * x + * + * + * ... + * ... + * > + * + * ---- + * ... + * ... + * ---- + * + * where the map matrix is a matrix of the following chars: + * W: Wall + * F: Field + * Z: Field with a ZMP + * B: Field with a Box + * O: Field with ONeill + * J: Field with Jaffa + * G: Gate + * S: Scale */ + Map buildDungeon(File input) throws IOException { Tile oneilllocation = null; Tile jaffalocation = null; @@ -17,8 +43,9 @@ public class Dungeon { Tile[][] dungeon = new Tile[width][height]; String line = null; - Gate gate = new Gate(); - Gate lastgate = gate; + Gate tempgate = new Gate(); + Scale tempscale = new Scale(tempgate, Integer.MAX_VALUE); + int scalecount = 0; for (int y = 0; y < height; ++y) { line = reader.readLine().replaceAll("\\s",""); // read line and remove whitespaces @@ -59,19 +86,27 @@ public class Dungeon { break; case 'G': - dungeon[y][x] = gate; - lastgate = gate; - gate = new Gate(); + dungeon[y][x] = tempgate; break; case 'S': - dungeon[y][x] = new Scale(lastgate, 5); + dungeon[y][x] = tempscale; + scalecount++; break; } } } - // NOTE: code seems to be correct till this point based on a debugger run-through + reader.readLine(); // throw empty line away + + for (int i = 0; i < scalecount; ++i) // set up scale-gate connections + { + String[] scaledata = reader.readLine().split("-"); + + dungeon[Integer.parseInt(scaledata[0])][Integer.parseInt(scaledata[1])] = + new Scale((Gate)dungeon[Integer.parseInt(scaledata[2])][Integer.parseInt(scaledata[3])], + Integer.parseInt(scaledata[4])); + } /* setting up Tile cross references */ for (int y = 0; y < height; ++y) @@ -100,6 +135,11 @@ public class Dungeon { } } } - return oneilllocation; + + Map playermap = new HashMap<>(); + playermap.put("oneill", oneilllocation); + playermap.put("jaffa", jaffalocation); + + return playermap; } } 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 From 0a4b00aad35607ac1ff158da945ecdb5e869d3d6 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 21:19:35 +0200 Subject: [PATCH 09/16] Tile-attributes changed Tile.itemOnTile no longer exists, it was replaced by boxStack and zpmOnTile. Getter-Setter methods were added. --- cicaprojekt/Tile.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/cicaprojekt/Tile.java b/cicaprojekt/Tile.java index 8ba3c6d..05f9868 100644 --- a/cicaprojekt/Tile.java +++ b/cicaprojekt/Tile.java @@ -2,10 +2,12 @@ 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(){ @@ -15,7 +17,7 @@ public abstract class Tile { adjacentTile.put(Direction.EAST, Field.testField); adjacentTile.put(Direction.SOUTH, Field.testField); adjacentTile.put(Direction.WEST, Field.testField); - itemOnTile = new Box(); + zpmOnTile = new ZPM(); } public Tile getAdjacentTile(Direction direction) { @@ -32,13 +34,17 @@ public abstract class Tile { public abstract void onExit(PlayerBase playerBase); - public Pickable removeItemFromTile() { - Pickable item = itemOnTile; - itemOnTile = null; - return item; + public ZPM getZPMFromTile() { + ZPM zpm = zpmOnTile; + zpmOnTile = null; + return zpm; } - public void setItemOnTile(Pickable item) { - itemOnTile = item; + public void putABox(Box box) { + boxStack.push(box); + } + + public Box getABox(){ + return boxStack.pop(); } } From 924a5acc261fc87495bcfaa3f073088767060b46 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 22:25:20 +0200 Subject: [PATCH 10/16] Tile refactored Every setItemOnTile call were replaced. --- cicaprojekt/Dungeon.java | 62 +++++++--------------------------------- cicaprojekt/Player.java | 4 +-- cicaprojekt/Tile.java | 14 +++++---- 3 files changed, 21 insertions(+), 59 deletions(-) diff --git a/cicaprojekt/Dungeon.java b/cicaprojekt/Dungeon.java index 2bc7815..79a98ea 100644 --- a/cicaprojekt/Dungeon.java +++ b/cicaprojekt/Dungeon.java @@ -1,35 +1,9 @@ package cicaprojekt; import java.io.*; -import java.util.HashMap; -import java.util.Map; public class Dungeon { - /* NOTE: this function assumes that the parameter input is a well-formatted dungeon file. - * Such file looks like as follows: - * - * x - * - * - * ... - * ... - * > - * - * ---- - * ... - * ... - * ---- - * - * where the map matrix is a matrix of the following chars: - * W: Wall - * F: Field - * Z: Field with a ZMP - * B: Field with a Box - * O: Field with ONeill - * J: Field with Jaffa - * G: Gate - * S: Scale */ - Map buildDungeon(File input) throws IOException + cicaprojekt.Tile buildDungeon(File input) throws IOException { Tile oneilllocation = null; Tile jaffalocation = null; @@ -43,9 +17,8 @@ public class Dungeon { Tile[][] dungeon = new Tile[width][height]; String line = null; - Gate tempgate = new Gate(); - Scale tempscale = new Scale(tempgate, Integer.MAX_VALUE); - int scalecount = 0; + Gate gate = new Gate(); + Gate lastgate = gate; for (int y = 0; y < height; ++y) { line = reader.readLine().replaceAll("\\s",""); // read line and remove whitespaces @@ -63,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; @@ -86,27 +59,19 @@ public class Dungeon { break; case 'G': - dungeon[y][x] = tempgate; + dungeon[y][x] = gate; + lastgate = gate; + gate = new Gate(); break; case 'S': - dungeon[y][x] = tempscale; - scalecount++; + dungeon[y][x] = new Scale(lastgate, 5); break; } } } - reader.readLine(); // throw empty line away - - for (int i = 0; i < scalecount; ++i) // set up scale-gate connections - { - String[] scaledata = reader.readLine().split("-"); - - dungeon[Integer.parseInt(scaledata[0])][Integer.parseInt(scaledata[1])] = - new Scale((Gate)dungeon[Integer.parseInt(scaledata[2])][Integer.parseInt(scaledata[3])], - Integer.parseInt(scaledata[4])); - } + // NOTE: code seems to be correct till this point based on a debugger run-through /* setting up Tile cross references */ for (int y = 0; y < height; ++y) @@ -135,11 +100,6 @@ public class Dungeon { } } } - - Map playermap = new HashMap<>(); - playermap.put("oneill", oneilllocation); - playermap.put("jaffa", jaffalocation); - - return playermap; + return oneilllocation; } } diff --git a/cicaprojekt/Player.java b/cicaprojekt/Player.java index b266db2..184f159 100644 --- a/cicaprojekt/Player.java +++ b/cicaprojekt/Player.java @@ -13,11 +13,11 @@ public class Player extends PlayerBase{ } 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; } diff --git a/cicaprojekt/Tile.java b/cicaprojekt/Tile.java index 05f9868..d8da251 100644 --- a/cicaprojekt/Tile.java +++ b/cicaprojekt/Tile.java @@ -12,12 +12,6 @@ public abstract class Tile { 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); - zpmOnTile = new ZPM(); } public Tile getAdjacentTile(Direction direction) { @@ -34,6 +28,10 @@ public abstract class Tile { public abstract void onExit(PlayerBase playerBase); + public void setZPMOnTile(ZPM zpm) { + zpmOnTile = zpm; + } + public ZPM getZPMFromTile() { ZPM zpm = zpmOnTile; zpmOnTile = null; @@ -41,10 +39,14 @@ public abstract class Tile { } public void putABox(Box box) { + if(box == null) + return; boxStack.push(box); } public Box getABox(){ + if(boxStack.isEmpty()) + return null; return boxStack.pop(); } } From a276a9e6e143de65ed9f832cb69d2e82b3fc185d Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 22:27:30 +0200 Subject: [PATCH 11/16] Field - finished --- cicaprojekt/Field.java | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/cicaprojekt/Field.java b/cicaprojekt/Field.java index e10e5b4..a9c38f6 100644 --- a/cicaprojekt/Field.java +++ b/cicaprojekt/Field.java @@ -3,40 +3,32 @@ package cicaprojekt; import java.util.HashMap; import java.util.Map; -public class Field extends Tile +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(Stargate stargate, Direction direction) { + public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { if (recursionLimit++ >= 10) this.adjacentTile.put(direction, new Wall()); 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.pickItem(); } - public void onExit() { + public void onExit(PlayerBase playerBase) { + return; } } From cbd196532f6cc2c899e9ca0c3ad81ccb6e5e1a34 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 22:28:09 +0200 Subject: [PATCH 12/16] Gap - finished --- cicaprojekt/Gap.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cicaprojekt/Gap.java b/cicaprojekt/Gap.java index fb1d807..a07d80a 100644 --- a/cicaprojekt/Gap.java +++ b/cicaprojekt/Gap.java @@ -1,16 +1,26 @@ package cicaprojekt; -public class Gap extends Tile +public class Gap extends cicaprojekt.Tile { + public Gap(){ + super(); + } + @Override - public void spawnStargate(Stargate stargate, Direction direction) { + 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(); } } From fd64fd9165c2ff7c65bbde38f362b06d09cea8ad Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 22:36:20 +0200 Subject: [PATCH 13/16] Gate - finished --- cicaprojekt/Gate.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cicaprojekt/Gate.java b/cicaprojekt/Gate.java index e67e526..e64ecdd 100644 --- a/cicaprojekt/Gate.java +++ b/cicaprojekt/Gate.java @@ -4,15 +4,26 @@ public class Gate extends Tile { private boolean open = false; - + 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() { From 1c8566d96c5eef4da2a47084d222587c52b86077 Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 22:36:54 +0200 Subject: [PATCH 14/16] Scale - finished --- cicaprojekt/Scale.java | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cicaprojekt/Scale.java b/cicaprojekt/Scale.java index 591512f..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,28 +11,34 @@ 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(); } From 69a23841600e2714d9926f6678fa98baf25f90aa Mon Sep 17 00:00:00 2001 From: ericnerdo Date: Sun, 24 Apr 2016 22:37:27 +0200 Subject: [PATCH 15/16] Wall - finished --- cicaprojekt/Wall.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cicaprojekt/Wall.java b/cicaprojekt/Wall.java index a6eed9e..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) @@ -15,16 +18,16 @@ public class Wall extends Tile { 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?"); } } From d0d656452c2e5f347e4a7c058b0a34fee2bcc83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 24 Apr 2016 22:48:17 +0200 Subject: [PATCH 16/16] implemented PlayerBase.pickZPM() (former pickItem()) callback method --- cicaprojekt/Field.java | 2 +- cicaprojekt/Player.java | 12 ++++++++++-- cicaprojekt/PlayerBase.java | 7 ++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cicaprojekt/Field.java b/cicaprojekt/Field.java index a9c38f6..69161c9 100644 --- a/cicaprojekt/Field.java +++ b/cicaprojekt/Field.java @@ -25,7 +25,7 @@ public class Field extends cicaprojekt.Tile return; playerBase.setCurrentTile(this); if(zpmOnTile != null) - playerBase.pickItem(); + playerBase.pickZPM(this); } public void onExit(PlayerBase playerBase) { diff --git a/cicaprojekt/Player.java b/cicaprojekt/Player.java index 184f159..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,6 +9,7 @@ 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 */ } @@ -20,8 +22,14 @@ public class Player extends PlayerBase{ 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: