diff --git a/.idea/misc.xml b/.idea/misc.xml index b573818..c3dfb30 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index 8549296..eaee90e 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -20,8 +20,7 @@ public class Siedler { throwDice(game, parser); diceThrown = true; } - - parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints()); + parser.displayPlayerInfo(game.getCurruntPlayerResource(), game.getCurrentPlayerWinpoints()); switch (parser.getAction()) { case NEXTPLAYER: Config.Faction winner = game.getWinner(); diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index f9fd45b..af4d862 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -385,40 +385,31 @@ public class SiedlerGame { * * @return the winner of the game or null, if there is no winner (yet) */ - public Faction getWinner() { - HashMap winPoints = getWinPoints(); - for(Faction faction : winPoints.keySet()){ - if(winPoints.get(faction) >= winPointsForWin){ - return faction; + public Faction getWinner() { + if(getCurrentPlayerWinpoints() >= winPointsForWin){ + return getCurrentPlayerFaction(); } + return null; } - return null; - } - private HashMap getWinPoints(){ - HashMap winPoints = new HashMap<>(); - List structures = board.getCorners(); - for(Structure structure : structures) { + public int getCurrentPlayerWinpoints(){ + int winPoints = 0; + List settlements = board.getCorners(); + for(Structure structure : settlements) { - int newWinPoints = 0; - if(structure instanceof City){ - newWinPoints = 2; - } else if(structure instanceof Settlement) { - newWinPoints = 1; + int newWinPoints = 0; + if(structure instanceof City){ + newWinPoints = 2; + } else if(structure instanceof Settlement) { + newWinPoints = 1; + } + if(structure.getFaction() == getCurrentPlayerFaction()){ + winPoints ++; + } } - - Faction faction = structure.getFaction(); - if(winPoints.containsKey(faction)) { - winPoints.put(faction, winPoints.get(faction) + newWinPoints); - } - else { - winPoints.put(faction, newWinPoints); - } - + //todo add points for longest road + return winPoints; } - //todo add points for longest road - return winPoints; - } /**