removed to do's and updated java docs.

This commit is contained in:
Speedy Gonzalez 2021-12-07 14:57:57 +01:00
parent 99da9715c5
commit cff925de61
2 changed files with 47 additions and 38 deletions

View File

@ -4,18 +4,21 @@ import java.util.*;
/** /**
* New Class PLayer * 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 { public class Player {
private Config.Faction faction; private Config.Faction faction;
private HashMap<Config.Resource,Integer> resources; private HashMap<Config.Resource, Integer> resources;
private HashMap<Config.Structure,Integer> structureToUse; private HashMap<Config.Structure, Integer> structureToUse;
private int roadsToUse;
private int settlementsToUse;
private int citiesToUse;
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 //Datenfelder
this.faction = faction; this.faction = faction;
//Verfügbare Structures initialisieren //Verfügbare Structures initialisieren
@ -25,36 +28,43 @@ public class Player {
structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer()); structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer());
//Ressourcen initialisiern //Ressourcen initialisiern
resources = new HashMap<>(); resources = new HashMap<>();
for(Config.Resource resource : Config.Resource.values()) { for (Config.Resource resource : Config.Resource.values()) {
resources.put(resource,0); resources.put(resource, 0);
} }
} }
/** /**
* This method returns all the resources the player has at the moment * This method returns all the resources the player has at the moment
*
* @return HashMap with the count of every resource * @return HashMap with the count of every resource
*/ */
public HashMap<Config.Resource,Integer> getResources() { public HashMap<Config.Resource, Integer> getResources() {
return resources; return resources;
} }
/** /**
* This method returns player faction * 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. * This method returns the amount of a specific resource that a player owns.
* @param resource *
* @return * @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 * This method adds a specific resource to resourcess
* @param resource to add *
* @param resource to add
* @param numberToAdd how much to add * @param numberToAdd how much to add
*/ */
public void addResource(Config.Resource resource, int numberToAdd) { 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. * 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 * @param numberToSubstract how much to substract
* @return true if resource has been substracted false if player has not enough resources * @return true if resource has been substracted false if player has not enough resources
*/ */
public boolean substractResource(Config.Resource resource, int numberToSubstract) { public boolean substractResource(Config.Resource resource, int numberToSubstract) {
int inPossesion = resources.get(resource); int inPossesion = resources.get(resource);
if(inPossesion - numberToSubstract < 0) { if (inPossesion - numberToSubstract < 0) {
return false; return false;
} }
resources.put(resource,inPossesion - numberToSubstract); resources.put(resource, inPossesion - numberToSubstract);
return true; 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 * 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. * 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<Config.Resource> costs = structure.getCosts(); List<Config.Resource> costs = structure.getCosts();
if(structureToUse.get(structure) < 1 || !checkResourceToBuild(costs)){ if (structureToUse.get(structure) < 1 || !checkResourceToBuild(costs)) {
return false; return false;
} }
structureToUse.put(structure, structureToUse.get(structure) - 1); structureToUse.put(structure, structureToUse.get(structure) - 1);
return true; return true;
} }
/**
* This method checks the amount of resources a player has in order to determine if he haas enough
//returns true if player has enough resources else false * 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<Config.Resource> list) { private boolean checkResourceToBuild(List<Config.Resource> list) {
HashMap<Config.Resource, Integer> costs = new HashMap<>(); HashMap<Config.Resource, Integer> costs = new HashMap<>();
for(Config.Resource resource : list){ for (Config.Resource resource : list) {
if(costs.containsKey(resource)){ if (costs.containsKey(resource)) {
costs.put(resource, costs.get(resource) + 1); costs.put(resource, costs.get(resource) + 1);
} else { } else {
costs.put(resource, 1); costs.put(resource, 1);
@ -111,6 +127,4 @@ public class Player {
} }
return true; return true;
} }
} }

View File

@ -161,7 +161,6 @@ public class SiedlerGame {
* @return true, if the placement was successful * @return true, if the placement was successful
*/ */
public boolean placeInitialSettlement(Point position, boolean payout) { public boolean placeInitialSettlement(Point position, boolean payout) {
// TODO: Implement
if(!validPositionForSettlement(position)){ if(!validPositionForSettlement(position)){
return false; return false;
} }
@ -186,7 +185,6 @@ public class SiedlerGame {
* @return true, if the placement was successful * @return true, if the placement was successful
*/ */
public boolean placeInitialRoad(Point roadStart, Point roadEnd) { public boolean placeInitialRoad(Point roadStart, Point roadEnd) {
// TODO: Implement
if (!validPositionForRoad(roadStart, roadEnd)){ if (!validPositionForRoad(roadStart, roadEnd)){
return false; return false;
} }
@ -228,7 +226,6 @@ public class SiedlerGame {
for (Point field : diceValueFields) { for (Point field : diceValueFields) {
List<Resource> resources = board.getResourcesforFaction(field,player.getFaction()); List<Resource> resources = board.getResourcesforFaction(field,player.getFaction());
for (Config.Resource resource : resources){ for (Config.Resource resource : resources){
//TODO: Check if Resource Null notwendig?
returnMap.get(player.getFaction()).add(resource); returnMap.get(player.getFaction()).add(resource);
addResourcesToPlayer(player, resource, 1); addResourcesToPlayer(player, resource, 1);
} }
@ -309,7 +306,6 @@ public class SiedlerGame {
* @return true, if the placement was successful * @return true, if the placement was successful
*/ */
public boolean buildCity(Point position) { public boolean buildCity(Point position) {
// TODO: OPTIONAL task - Implement
//1. Check if Corner. //1. Check if Corner.
if (!board.hasCorner(position)){ if (!board.hasCorner(position)){
return false; return false;
@ -356,7 +352,6 @@ public class SiedlerGame {
} }
//2. Can Player build road //2. Can Player build road
if (!allPlayers.get(activePlayer).build(Config.Structure.ROAD)) { if (!allPlayers.get(activePlayer).build(Config.Structure.ROAD)) {
// TODO: Error message
return false; return false;
} }