From 7129435feae87f1d5e6ab128675f149193524d1e Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 3 Dec 2021 16:39:11 +0100 Subject: [PATCH] SiedlerGame throwDice method implemented (for 7 not yet implemented) and method getResourcesforFaction implemented in SiedlerBoard --- src/ch/zhaw/catan/Parser.java | 2 +- src/ch/zhaw/catan/SiedlerBoard.java | 15 +++++++++++++++ src/ch/zhaw/catan/SiedlerGame.java | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/ch/zhaw/catan/Parser.java b/src/ch/zhaw/catan/Parser.java index 1a4c6dd..b298b74 100644 --- a/src/ch/zhaw/catan/Parser.java +++ b/src/ch/zhaw/catan/Parser.java @@ -26,7 +26,7 @@ public class Parser { } public void displayPlayerInfo(HashMap currentPlayerResource, int winpoints){ - textTerminal.println("You are currently holding" + winpoints + " winpoints."); + textTerminal.println("You are currently holding " + winpoints + " winpoints."); textTerminal.println("You own the follwing resources:"); for(Config.Resource resource : currentPlayerResource.keySet()){ textTerminal.println(resource.name() + ":" + currentPlayerResource.get(resource)); diff --git a/src/ch/zhaw/catan/SiedlerBoard.java b/src/ch/zhaw/catan/SiedlerBoard.java index d560b7a..864a217 100644 --- a/src/ch/zhaw/catan/SiedlerBoard.java +++ b/src/ch/zhaw/catan/SiedlerBoard.java @@ -66,6 +66,21 @@ public class SiedlerBoard extends HexBoard { return fields; } + + public ArrayList getResourcesforFaction(Point point, Config.Faction faction){ + List possibleSettlementField = super.getCornersOfField(point); + ArrayList resourcesToPlayer = new ArrayList<>(); + for (Structure structure : possibleSettlementField) { + if (structure.getFaction() == faction) { + resourcesToPlayer.add(fields.get(point).getResource()); + if (structure instanceof City) { + resourcesToPlayer.add(fields.get(point).getResource()); + } + } + } + return resourcesToPlayer; + } + /** * Returns the {@link Land}s adjacent to the specified corner. * diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 1842179..2b8b00c 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -198,8 +198,19 @@ public class SiedlerGame { * @return the resource cards added to the stock of the different players */ public Map> throwDice(int dicethrow) { - // TODO: Implement - return null; + Map> returnMap= new HashMap<>(); + List diceValueFields = board.getFieldsForDiceValue(dicethrow); + for (Player player : allPlayers) { + returnMap.put(player.getFaction(), new ArrayList()); + for (Point field : diceValueFields) { + List resources= board.getResourcesforFaction(field,player.getFaction()); + for (Config.Resource resource : resources){ + returnMap.get(player.getFaction()).add(resource); + player.addResource(resource,1); + } + } + } + return returnMap; } /**