Update TimeGoal.java
Edge Case, runden auf 6 erhöht
This commit is contained in:
parent
8e5660a370
commit
507c8f466f
1 changed files with 16 additions and 6 deletions
|
|
@ -18,12 +18,13 @@ import game.map.Castle;
|
|||
public class TimeGoal extends Goal {
|
||||
|
||||
int maxRounds;
|
||||
boolean isDraw;
|
||||
|
||||
/**
|
||||
* Creates a new time goal with the default limit
|
||||
*/
|
||||
public TimeGoal() {
|
||||
this(4);
|
||||
this(6);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -33,11 +34,14 @@ public class TimeGoal extends Goal {
|
|||
public TimeGoal(int maxRounds) {
|
||||
super("Countdown", "Derjenige Spieler gewinnt, der nach " + maxRounds + " Runden die meisten Burgen besitzt.");
|
||||
this.maxRounds = maxRounds;
|
||||
isDraw = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompleted() {
|
||||
return this.getWinner() != null;
|
||||
// Call getWinner to set isDraw if needed
|
||||
getWinner();
|
||||
return isDraw || this.getWinner() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -75,17 +79,23 @@ public class TimeGoal extends Goal {
|
|||
}
|
||||
|
||||
};
|
||||
System.out.println(Collections.max(playerList, comp).getNumRegions(game));
|
||||
System.out.println(Collections.max(playerList, comp).getName());
|
||||
Collections.sort(playerList, comp);
|
||||
// Edge Case: Mehrere Spieler haben auch die gleiche Anzahl an Regionen. Dann gibt es ein Draw.
|
||||
// Edge Case: Mind. Zwei spieler haben die gleiche Anzahl an Burgen
|
||||
if(playerList.get(0).getNumRegions(game) == playerList.get(1).getNumRegions(game)) {
|
||||
isDraw = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
return Collections.max(playerList, comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLost(Player player) {
|
||||
|
||||
if(getGame().getRound() < maxRounds)
|
||||
if(getGame().getRound() < 2)
|
||||
return false;
|
||||
|
||||
return !player.equals(getWinner());
|
||||
return player.getNumRegions(getGame()) == 0 || (this.isCompleted() && !player.equals(this.getWinner()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue