diff --git a/src/ch/zhaw/catan/Player.java b/src/ch/zhaw/catan/Player.java index d7b7bc3..2011fe8 100644 --- a/src/ch/zhaw/catan/Player.java +++ b/src/ch/zhaw/catan/Player.java @@ -13,6 +13,7 @@ public class Player { private HashMap resources; private int roadsToUse; private int settlementsToUse; + private int citiesToUse; public Player (Config.Faction faction){ //Datenfelder @@ -91,9 +92,9 @@ public class Player { /** * This method has to be used when a player wants to build a settlement. It checks if a player has enough roads - * and resources to build one more. If player is able to build, the method substract the buildcost from the resources - * in possesion by the player. - * @return true if road can be created false if road can't be created + * and resources to build one more. If the player is able to build, this method subtracts the buildcost from the resources + * in possession by the player. + * @return true if road can be created false if road can't be created. */ public boolean buildSettlement() { List costs = Config.Structure.SETTLEMENT.getCosts(); @@ -106,6 +107,23 @@ public class Player { return true; } + /** + * This method has to be used when a player wants to build a city. It checks if a player already has a settlement + * on that position and if he has enough resource to build one. If the player is able to build, this method subtracts + * the buildcost from the resources in possession by the player. + * @return true if road can be created false if road can't be created. + */ + public boolean buildCity() { + List costs = Config.Structure.CITY.getCosts(); + if ( citiesToUse == 0 || !checkRessourceToBuild(costs)){ + return false; + } + for (Config.Resource resource : costs){ + resources.put(resource,resources.get(resource)-1); + } + return true; + } + //returns true if player has enough resources else false private boolean checkRessourceToBuild(List liste) { for (Config.Resource resource : liste) { diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index df260e2..a9a9463 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -218,7 +218,7 @@ public class SiedlerGame { } //4. Insert Settlement to map board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction())); - //5. Give Resoure to bank + //5. Give Resources to bank bank.storeResourceToBank(Config.Structure.SETTLEMENT.getCosts()); return true; } @@ -238,6 +238,21 @@ public class SiedlerGame { */ public boolean buildCity(Point position) { // TODO: OPTIONAL task - Implement + //1. Check if Corner. + if (!board.hasCorner(position)){ + return false; + } + //2. Check if Settlement has already been built + Settlement atCurrentPosition = (Settlement) board.getCorner(position); + + //3. Can player build a City. + if(!allPlayers.get(activePlayer).buildCity()){ + return false; + } + //4.Insert City into the map. + board.setCorner(position,new City(allPlayers.get(activePlayer).getFaction())); + //5. Give resources to the bank. + bank.storeResourceToBank(Config.Structure.CITY.getCosts()); return false; }