diff --git a/src/ch/zhaw/catan/Bank.java b/src/ch/zhaw/catan/Bank.java new file mode 100644 index 0000000..6b498c4 --- /dev/null +++ b/src/ch/zhaw/catan/Bank.java @@ -0,0 +1,36 @@ +package ch.zhaw.catan; + +import java.util.Map; + +public class Bank { + private Map resources; + + public Bank(){ + resources = Config.INITIAL_RESOURCE_CARDS_BANK; + + } + + public boolean getResourceFromBank(Config.Resource resource,int numberOfResources) { + if(resources.get(resource) >= numberOfResources) { + Integer newResourceNumber = resources.get(resource) - numberOfResources; + resources.put(resource, newResourceNumber); + return true; + } + else { + return false; + } + } + + public boolean tradeWithBank(Config.Resource resourceToReceive, Config.Resource resourceToGive) { + if(resources.get(resourceToReceive) >= 1){ + Integer newResourceReceived = resources.get(resourceToReceive) + 4; + Integer newResourcesGiven = resources.get(resourceToGive) - 1; + resources.put(resourceToReceive, newResourceReceived); + resources.put(resourceToGive, newResourcesGiven); + return true; + } + else{ + return false; + } + } +}