diff --git a/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java b/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java index 3df0cc3..85f5d1e 100644 --- a/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java +++ b/Projektgruppe_175/src/game/goals/CaptureTheFlagGoal.java @@ -14,11 +14,11 @@ public class CaptureTheFlagGoal extends Goal { final static boolean DEBUG = true; - final static int ROUND_FOR_DISTRIBUTION = 2; final static int MIN_ROUND_FOR_WIN = 2; - final static int NUM_FLAG_CASTLES = 4; + final static int NUM_FLAG_CASTLES_MULTIPLIER = 2; List flagCastles; + int numFlagCastles; private static Random random = new Random(); private static int newRandomInt(int min, int max) { @@ -27,9 +27,20 @@ public class CaptureTheFlagGoal extends Goal { public CaptureTheFlagGoal() { super("Capture the flag", "Derjenige Spieler gewinnt, der zuerst" - + " alle " + NUM_FLAG_CASTLES + " Flaggen-Schlösser erobert."); + + " alle weiß umrandeten Flaggen-Schlösser erobert."); flagCastles = new ArrayList(); + + if (DEBUG) + System.out.println("Creating capture the flag goal instance"); + } + + @Override + public void setGame(Game game) { + + super.setGame(game); + numFlagCastles = this.getGame().getPlayers().size() * NUM_FLAG_CASTLES_MULTIPLIER; + } @Override @@ -37,12 +48,10 @@ public class CaptureTheFlagGoal extends Goal { if (DEBUG) System.out.println("Checking is completed"); - - Game game = this.getGame(); - + // As this function is called every round, // let's check if we can set the flag castles - if (flagCastles.isEmpty() && game.getRound() >= ROUND_FOR_DISTRIBUTION) { + if (flagCastles.isEmpty() && canCommenceDistribution()) { if (DEBUG) System.out.println("Distributing"); distributeFlagCastles(); @@ -105,9 +114,9 @@ public class CaptureTheFlagGoal extends Goal { List players = game.getPlayers(); int numCastlesToDistribute = - /*if*/ NUM_FLAG_CASTLES < players.size() ? + /*if*/ numFlagCastles < players.size() ? /*then*/ players.size() : - /*else*/ NUM_FLAG_CASTLES; + /*else*/ numFlagCastles; for (int i = 0; i < players.size(); i++) { @@ -163,6 +172,21 @@ public class CaptureTheFlagGoal extends Goal { } - + /** + * Returns whether the game is in a state ready for castle distribution + * @return + */ + private boolean canCommenceDistribution() { + + Game game = this.getGame(); + + for (Castle castle : game.getMap().getCastles()) { + if (castle.getOwner() == null) + return false; + } + + return true; + + } }