Improve CaptureTheFlagGoal
This commit is contained in:
parent
745b86a8f3
commit
f49bf02441
1 changed files with 34 additions and 10 deletions
|
|
@ -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<Castle> 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<Castle>();
|
||||
|
||||
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
|
||||
|
|
@ -38,11 +49,9 @@ 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<Player> 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue