From b0af4c82a11485f8f201e5d9feaf714a93eaa020 Mon Sep 17 00:00:00 2001 From: Dennis Weinberger Date: Thu, 21 Mar 2019 14:57:40 +0000 Subject: [PATCH] new time goal --- .../src/game/goals/TimeGoal.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Projektgruppe_175/src/game/goals/TimeGoal.java diff --git a/Projektgruppe_175/src/game/goals/TimeGoal.java b/Projektgruppe_175/src/game/goals/TimeGoal.java new file mode 100644 index 0000000..50e8d3c --- /dev/null +++ b/Projektgruppe_175/src/game/goals/TimeGoal.java @@ -0,0 +1,73 @@ +package game.goals; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import game.Game; +import game.Goal; +import game.Player; +import game.map.Castle; + +public class TimeGoal extends Goal { + + int maxRounds = 4; + + public TimeGoal() { + super("Countdown", "Derjenige Spieler gewinnt, der nach 10 Runden die meisten Burgen besitzt."); + } + + @Override + public boolean isCompleted() { + return this.getWinner() != null; + } + + @Override + public Player getWinner() { + + Game game = this.getGame(); + + // If a player conquers all castles before the time limit is over, the game should obviously end there. + if(game.getRound() < maxRounds) { + + // Copy-pasted from ConquerGoal.java + if(game.getRound() < 2) + return null; + + Player p = null; + for(Castle c : game.getMap().getCastles()) { + if(c.getOwner() == null) + return null; + else if(p == null) + p = c.getOwner(); + else if(p != c.getOwner()) + return null; + } + + return p; + } + + List playerList = game.getPlayers(); + Comparator comp = new Comparator() { + + public int compare(Player p1, Player p2) { + + return Integer.compare(p1.getNumRegions(game), p2.getNumRegions(game)); + + } + + }; + System.out.println(Collections.max(playerList, comp).getNumRegions(game)); + System.out.println(Collections.max(playerList, comp).getName()); + return Collections.max(playerList, comp); + } + + @Override + public boolean hasLost(Player player) { + + if(getGame().getRound() < maxRounds) + return false; + + return !player.equals(getWinner()); + } +}