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 {
|
public class TimeGoal extends Goal {
|
||||||
|
|
||||||
int maxRounds;
|
int maxRounds;
|
||||||
|
boolean isDraw;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new time goal with the default limit
|
* Creates a new time goal with the default limit
|
||||||
*/
|
*/
|
||||||
public TimeGoal() {
|
public TimeGoal() {
|
||||||
this(4);
|
this(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,11 +34,14 @@ public class TimeGoal extends Goal {
|
||||||
public TimeGoal(int maxRounds) {
|
public TimeGoal(int maxRounds) {
|
||||||
super("Countdown", "Derjenige Spieler gewinnt, der nach " + maxRounds + " Runden die meisten Burgen besitzt.");
|
super("Countdown", "Derjenige Spieler gewinnt, der nach " + maxRounds + " Runden die meisten Burgen besitzt.");
|
||||||
this.maxRounds = maxRounds;
|
this.maxRounds = maxRounds;
|
||||||
|
isDraw = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
return this.getWinner() != null;
|
// Call getWinner to set isDraw if needed
|
||||||
|
getWinner();
|
||||||
|
return isDraw || this.getWinner() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -75,17 +79,23 @@ public class TimeGoal extends Goal {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
System.out.println(Collections.max(playerList, comp).getNumRegions(game));
|
Collections.sort(playerList, comp);
|
||||||
System.out.println(Collections.max(playerList, comp).getName());
|
// 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);
|
return Collections.max(playerList, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasLost(Player player) {
|
public boolean hasLost(Player player) {
|
||||||
|
|
||||||
if(getGame().getRound() < maxRounds)
|
if(getGame().getRound() < 2)
|
||||||
return false;
|
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