fixing Method checkResourceToBuild

This commit is contained in:
schrom01 2021-12-07 11:44:51 +01:00
parent da6913d997
commit 4c56518ba0
2 changed files with 16 additions and 10 deletions

View File

@ -95,10 +95,17 @@ public class Player {
//returns true if player has enough resources else false //returns true if player has enough resources else false
private boolean checkRessourceToBuild(List<Config.Resource> liste) { private boolean checkResourceToBuild(List<Config.Resource> list) {
for (Config.Resource resource : liste) { HashMap<Config.Resource, Integer> costs = new HashMap<>();
int possesion = resources.get(resource); for(Config.Resource resource : list){
if (possesion == 0) { if(costs.containsKey(resource)){
costs.put(resource, costs.get(resource) + 1);
} else {
costs.put(resource, 1);
}
}
for (Config.Resource resource : costs.keySet()) {
if (resources.get(resource) < costs.get(resource)) {
return false; return false;
} }
} }
@ -106,5 +113,4 @@ public class Player {
} }
} }