From 8811410e442ada497f6c493d977cc75714dab8e8 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Fri, 3 Dec 2021 09:37:19 +0100 Subject: [PATCH] change in Main Method changed Method getWinner and getCurrentPlayerWinpoints --- src/ch/zhaw/catan/Siedler.java | 18 +++++++++++++----- src/ch/zhaw/catan/SiedlerGame.java | 21 ++++++--------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/ch/zhaw/catan/Siedler.java b/src/ch/zhaw/catan/Siedler.java index 5088591..8549296 100644 --- a/src/ch/zhaw/catan/Siedler.java +++ b/src/ch/zhaw/catan/Siedler.java @@ -13,13 +13,15 @@ public class Siedler { boolean running = true; boolean diceThrown = false; while (running){ + Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction(); parser.displayGameboard(game.getBoard().getTextView()); - parser.playerTurn(game.getCurrentPlayerFaction()); + parser.playerTurn(currentPlayerFaction); if(!diceThrown) { throwDice(game, parser); diceThrown = true; } - parser.displayPlayerInfo(game.getCurrentPlayerResource(),game.getWinPoints().get(game.getCurrentPlayerFaction())); + + parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinpoints()); switch (parser.getAction()) { case NEXTPLAYER: Config.Faction winner = game.getWinner(); @@ -33,15 +35,21 @@ public class Siedler { break; case BUILDSETTLEMENT: parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT); - game.buildSettlement(parser.getPoint()); + if(!game.buildSettlement(parser.getPoint())){ + parser.errorMessage(); + } break; case BUILDCITY: parser.giveCoordinatesForStructures(Config.Structure.CITY); - game.buildCity(parser.getPoint()); + if(!game.buildCity(parser.getPoint())){ + parser.errorMessage(); + } break; case BUILDROAD: parser.giveCoordinatesForStructures(Config.Structure.ROAD); - game.buildRoad(parser.getPoint(), parser.getPoint()); + if(game.buildRoad(parser.getPoint(), parser.getPoint())){ + parser.errorMessage(); + } break; case TRADEWITHBANK: Config.Resource offer = parser.trade(true); diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 8298fd9..4df7ee6 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -314,17 +314,14 @@ 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; - } + if(getCurrentPlayerWinpoints() >= winPointsForWin){ + return getCurrentPlayerFaction(); } return null; } - public HashMap getWinPoints(){ - HashMap winPoints = new HashMap<>(); + public int getCurrentPlayerWinpoints(){ + int winPoints = 0; List structures = board.getCorners(); for(Structure structure : structures) { @@ -334,15 +331,9 @@ public class SiedlerGame { } else if(structure instanceof Settlement) { newWinPoints = 1; } - - Faction faction = structure.getFaction(); - if(winPoints.containsKey(faction)) { - winPoints.put(faction, winPoints.get(faction) + newWinPoints); + if(structure.getFaction() == getCurrentPlayerFaction()){ + winPoints ++; } - else { - winPoints.put(faction, newWinPoints); - } - } //todo add points for longest road return winPoints;