Added method buildCity.

This commit is contained in:
Speedy Gonzalez
2021-12-03 09:48:30 +01:00
parent 1e49424b9c
commit 70b27af038
2 changed files with 37 additions and 4 deletions
+21 -3
View File
@@ -13,6 +13,7 @@ public class Player {
private HashMap<Config.Resource,Integer> 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<Config.Resource> 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<Config.Resource> 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<Config.Resource> liste) {
for (Config.Resource resource : liste) {