Merge remote-tracking branch 'origin/main'

This commit is contained in:
schrom01 2021-12-04 16:34:12 +01:00
commit 5eece3125b
1 changed files with 3 additions and 15 deletions

View File

@ -1,13 +1,14 @@
package ch.zhaw.catan; package ch.zhaw.catan;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class Bank { public class Bank {
private Map<Config.Resource, Integer> resources; private HashMap<Config.Resource, Integer> resources;
public Bank(){ public Bank(){
resources = Config.INITIAL_RESOURCE_CARDS_BANK; resources.putAll(Config.INITIAL_RESOURCE_CARDS_BANK);
} }
@ -27,17 +28,4 @@ public class Bank {
return false; return false;
} }
} }
public boolean tradeWithBank(Config.Resource resourceToReceive, Config.Resource resourceToGive, int toWant, int toGive) {
if(resources.get(resourceToReceive) >= toWant){
Integer newResourceReceived = resources.get(resourceToReceive) + toGive;
Integer newResourcesGiven = resources.get(resourceToGive) - toWant;
resources.put(resourceToReceive, newResourceReceived);
resources.put(resourceToGive, newResourcesGiven);
return true;
}
else{
return false;
}
}
} }