From 314428b273c7fbcf95a6942455d5cd6c97e4c58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bokros=20B=C3=A1lint?= Date: Fri, 13 May 2016 18:14:14 +0200 Subject: [PATCH] Refactored spawnStargate, with default implementation in base class --- cicaprojekt/Field.java | 10 ---------- cicaprojekt/Gap.java | 5 ----- cicaprojekt/Gate.java | 1 + cicaprojekt/Scale.java | 4 ---- cicaprojekt/Tile.java | 4 +++- cicaprojekt/Wall.java | 5 +++-- 6 files changed, 7 insertions(+), 22 deletions(-) diff --git a/cicaprojekt/Field.java b/cicaprojekt/Field.java index c637a6f..5888e82 100644 --- a/cicaprojekt/Field.java +++ b/cicaprojekt/Field.java @@ -4,9 +4,6 @@ import java.util.HashMap; import java.util.Map; public class Field extends cicaprojekt.Tile { - private static int recursionLimit = 0; - - public Field() { super(); } @@ -19,13 +16,6 @@ public class Field extends cicaprojekt.Tile { return false; } - @Override - 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(PlayerBase playerBase) { if (boxStack.size() > 0) return; diff --git a/cicaprojekt/Gap.java b/cicaprojekt/Gap.java index fb66b74..0944647 100644 --- a/cicaprojekt/Gap.java +++ b/cicaprojekt/Gap.java @@ -11,11 +11,6 @@ public class Gap extends cicaprojekt.Tile { return true; } - @Override - public void spawnStargate(cicaprojekt.Stargate stargate, Direction direction) { - adjacentTile.get(direction).spawnStargate(stargate, direction); - } - public void onEntry(PlayerBase playerBase) { playerBase.destroy(); } diff --git a/cicaprojekt/Gate.java b/cicaprojekt/Gate.java index 4092bb7..362fe63 100644 --- a/cicaprojekt/Gate.java +++ b/cicaprojekt/Gate.java @@ -7,6 +7,7 @@ public class Gate extends Tile { super(); } + @Override 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 515083d..6b613cc 100644 --- a/cicaprojekt/Scale.java +++ b/cicaprojekt/Scale.java @@ -51,10 +51,6 @@ public class Scale extends Field { stackChanged(); } - public void spawnStargate(Stargate stargate, Direction direction) { - adjacentTile.get(direction).spawnStargate(stargate, direction); - } - private void stackChanged() { if (weight > threshold) gateConnected.setOpen(true); diff --git a/cicaprojekt/Tile.java b/cicaprojekt/Tile.java index f3c28c1..69d2eb3 100644 --- a/cicaprojekt/Tile.java +++ b/cicaprojekt/Tile.java @@ -41,7 +41,9 @@ public abstract class Tile { adjacentTile.put(direction, newTile); } - public abstract void spawnStargate(Stargate stargate, Direction direction); + public void spawnStargate(Stargate stargate, Direction direction) { + adjacentTile.get(direction).spawnStargate(stargate, direction); + } public abstract void onEntry(PlayerBase playerBase); diff --git a/cicaprojekt/Wall.java b/cicaprojekt/Wall.java index ca84416..ccc1112 100644 --- a/cicaprojekt/Wall.java +++ b/cicaprojekt/Wall.java @@ -1,18 +1,19 @@ package cicaprojekt; public class Wall extends Tile { - private Stargate sg; + private Stargate sg = null; public Wall() { super(); } + @Override public void spawnStargate(Stargate stargate, Direction direction) { clearStargate(); if (sg == null) { sg = stargate; sg.setCurrentWall(this); - + Game.instance.updateDisplay(); } else return;