From cff925de61bd8c87b5c6a0c24d8d0356b19d3d4c Mon Sep 17 00:00:00 2001 From: Speedy Gonzalez Date: Tue, 7 Dec 2021 14:57:57 +0100 Subject: [PATCH] removed to do's and updated java docs. --- src/ch/zhaw/catan/Player.java | 80 ++++++++++++++++++------------ src/ch/zhaw/catan/SiedlerGame.java | 5 -- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/ch/zhaw/catan/Player.java b/src/ch/zhaw/catan/Player.java index 4f49428..dbe2690 100644 --- a/src/ch/zhaw/catan/Player.java +++ b/src/ch/zhaw/catan/Player.java @@ -4,18 +4,21 @@ import java.util.*; /** * New Class PLayer - * This class is here to add players to the game. + * This class is here in order to maintain the resources of the players, the amount of structures that they can build, + * control to see if a player has enough to build a new structure and to add them into a faction. */ public class Player { private Config.Faction faction; - private HashMap resources; - private HashMap structureToUse; - private int roadsToUse; - private int settlementsToUse; - private int citiesToUse; + private HashMap resources; + private HashMap structureToUse; - public Player (Config.Faction faction){ + /** + * The constructor creates a new instance of the player class that initializes the Hashmap resources and structureToUse. + * + * @param faction this is the faction of the player. + */ + public Player(Config.Faction faction) { //Datenfelder this.faction = faction; //Verfügbare Structures initialisieren @@ -25,36 +28,43 @@ public class Player { structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer()); //Ressourcen initialisiern resources = new HashMap<>(); - for(Config.Resource resource : Config.Resource.values()) { - resources.put(resource,0); + for (Config.Resource resource : Config.Resource.values()) { + resources.put(resource, 0); } } - /** * This method returns all the resources the player has at the moment + * * @return HashMap with the count of every resource */ - public HashMap getResources() { + public HashMap getResources() { return resources; } /** * This method returns player faction - * @return + * + * @return the faction of the player. */ - public Config.Faction getFaction() { return faction; } + public Config.Faction getFaction() { + return faction; + } /** - * This method returns for specific resource how much player possesess. - * @param resource - * @return + * This method returns the amount of a specific resource that a player owns. + * + * @param resource the resource that is needed. + * @return the amount of the specific resource. */ - public int getSpecificResource(Config.Resource resource) { return resources.get(resource); } + public int getSpecificResource(Config.Resource resource) { + return resources.get(resource); + } /** * This method adds a specific resource to resourcess - * @param resource to add + * + * @param resource to add * @param numberToAdd how much to add */ public void addResource(Config.Resource resource, int numberToAdd) { @@ -63,42 +73,48 @@ public class Player { /** * This method substracts a specific resource from resourcess but check first if player has enough resources. - * @param resource to substract + * + * @param resource to substract * @param numberToSubstract how much to substract * @return true if resource has been substracted false if player has not enough resources */ public boolean substractResource(Config.Resource resource, int numberToSubstract) { int inPossesion = resources.get(resource); - if(inPossesion - numberToSubstract < 0) { + if (inPossesion - numberToSubstract < 0) { return false; } - resources.put(resource,inPossesion - numberToSubstract); + resources.put(resource, inPossesion - numberToSubstract); return true; } - //todo java doc aktualisieren /** - * This method has to be used when a player wants to build a settlement. It checks if a player has enough roads + * This method has to be used when a player wants to build a structure. It checks if a player has enough of the specific structure * 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. + * It reduces the amount of the specific structure a player can build by 1. + * @return true if the structure can be created false if the structure can't be created. */ - public boolean build(Config.Structure structure){ + public boolean build(Config.Structure structure) { List costs = structure.getCosts(); - if(structureToUse.get(structure) < 1 || !checkResourceToBuild(costs)){ + if (structureToUse.get(structure) < 1 || !checkResourceToBuild(costs)) { return false; } structureToUse.put(structure, structureToUse.get(structure) - 1); return true; } - - - //returns true if player has enough resources else false + /** + * This method checks the amount of resources a player has in order to determine if he haas enough + * resources to build a new structure. + * + * @param list the list that shows how many resources are required. + * @return true if the player has enough resources to build and return false if he doesn't. + */ + //returns true if player has enough resources else false private boolean checkResourceToBuild(List list) { HashMap costs = new HashMap<>(); - for(Config.Resource resource : list){ - if(costs.containsKey(resource)){ + for (Config.Resource resource : list) { + if (costs.containsKey(resource)) { costs.put(resource, costs.get(resource) + 1); } else { costs.put(resource, 1); @@ -111,6 +127,4 @@ public class Player { } return true; } - - } diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 6f488ad..fa64686 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -161,7 +161,6 @@ public class SiedlerGame { * @return true, if the placement was successful */ public boolean placeInitialSettlement(Point position, boolean payout) { - // TODO: Implement if(!validPositionForSettlement(position)){ return false; } @@ -186,7 +185,6 @@ public class SiedlerGame { * @return true, if the placement was successful */ public boolean placeInitialRoad(Point roadStart, Point roadEnd) { - // TODO: Implement if (!validPositionForRoad(roadStart, roadEnd)){ return false; } @@ -228,7 +226,6 @@ 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); addResourcesToPlayer(player, resource, 1); } @@ -309,7 +306,6 @@ public class SiedlerGame { * @return true, if the placement was successful */ public boolean buildCity(Point position) { - // TODO: OPTIONAL task - Implement //1. Check if Corner. if (!board.hasCorner(position)){ return false; @@ -356,7 +352,6 @@ public class SiedlerGame { } //2. Can Player build road if (!allPlayers.get(activePlayer).build(Config.Structure.ROAD)) { - // TODO: Error message return false; }