From 79cc4f3f3c06ae2ee047668edb5727ce3dfc3602 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 25 Nov 2021 17:26:18 +0100 Subject: [PATCH 1/2] New Class Road Start to edit SiedlerGame.buildRoad --- .gitignore | 1 + .idea/.gitignore | 2 +- .idea/misc.xml | 2 +- src/ch/zhaw/catan/Road.java | 22 ++++++++++++++++++++++ src/ch/zhaw/catan/SiedlerGame.java | 7 +++++++ 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 src/ch/zhaw/catan/Road.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a3417b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/out/ diff --git a/.idea/.gitignore b/.idea/.gitignore index 73f69e0..0047fc0 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -5,4 +5,4 @@ /dataSources/ /dataSources.local.xml # Editor-based HTTP Client requests -/httpRequests/ +/httpRequests/ \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c3dfb30..1029788 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/Road.java b/src/ch/zhaw/catan/Road.java new file mode 100644 index 0000000..7ba52c8 --- /dev/null +++ b/src/ch/zhaw/catan/Road.java @@ -0,0 +1,22 @@ +package ch.zhaw.catan; + +import java.util.HashMap; + +/** + * This Class represents a Road Object. It informs about the ressources needed to build a road + */ +public class Road { + + final private HashMap buildCost; + + public Road() { + buildCost = new HashMap<>(); + buildCost.put(Config.Resource.LUMBER, 1); + buildCost.put(Config.Resource.BRICK, 1); + } + + public HashMap getBuildCost() { + return buildCost; + } + +} diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 48405eb..64f6632 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -213,6 +213,13 @@ public class SiedlerGame { */ public boolean buildRoad(Point roadStart, Point roadEnd) { // TODO: Implement + // 0.Is Edge 1. Check if Edge is empty 2. Check if One neighbors Corner is own settlement 3. Set road + boolean validTask = true; + while (validTask) { + validTask = board.hasEdge(roadStart,roadEnd); + validTask = board.getEdge(roadStart,roadEnd) == null; + } + return false; } From 4a352dd40afbb0b2e982f9dd9c2847fe2f406c13 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Sat, 4 Dec 2021 14:02:06 +0100 Subject: [PATCH 2/2] Fixed Bug set strutcture in water and set bug addressource nullpointer exception --- src/ch/zhaw/catan/SiedlerGame.java | 31 ++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 2b8b00c..5f87c31 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -154,7 +154,9 @@ public class SiedlerGame { board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction())); List lands = board.getLandsForCorner(position); for (Config.Land land:lands){ - allPlayers.get(activePlayer).addResource(land.getResource(), 1); + if(land.getResource()!=null){ + allPlayers.get(activePlayer).addResource(land.getResource(), 1); + } } return true; } @@ -205,6 +207,7 @@ public class SiedlerGame { for (Point field : diceValueFields) { List resources= board.getResourcesforFaction(field,player.getFaction()); for (Config.Resource resource : resources){ + //TODO: Check if Resource Null notwendig? returnMap.get(player.getFaction()).add(resource); player.addResource(resource,1); } @@ -330,10 +333,12 @@ public class SiedlerGame { } //3. Check if NeighbourEdge are Roads boolean hasNeighbourRoad = (checkAdjacentEdgesList(roadStart) || checkAdjacentEdgesList(roadEnd)); - //4.Check if roadStart or roadEnd is Settlement of current player or if 3. is valid - if(board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction() - || board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction() - || hasNeighbourRoad){ + if(hasNeighbourRoad) { + return true; + } + //4.Check if roadStart or roadEnd is Settlement of current player + if((board.getCorner(roadStart)!=null && board.getCorner(roadStart).getFaction() == allPlayers.get(activePlayer).getFaction()) + ||(board.getCorner(roadEnd)!=null && board.getCorner(roadEnd).getFaction() == allPlayers.get(activePlayer).getFaction())) { return true; } return false; @@ -349,7 +354,11 @@ public class SiedlerGame { if (!board.hasCorner(position)) { return false; } - //2. Check if Corner is empty + //2. Check if water + if(checkIfWater(position)) { + return false; + } + //3. Check if Corner is empty if(board.getCorner(position) != null) { return false; } @@ -360,6 +369,16 @@ public class SiedlerGame { return true; } + private boolean checkIfWater(Point point) { + List fields = board.getFields(point); + for(Config.Land land : fields) { + if(!land.equals(Config.Land.WATER)) { + return false; + } + } + return true; + } + /** * This method checks if there are Roads build by active Player on adjacent edges * @param point