gruppe06-hufflepuff-projekt.../src/ch/zhaw/catan/Bank.java

48 lines
1.7 KiB
Java

package ch.zhaw.catan;
import java.util.HashMap;
/**
* Bank Class that stores Resources when not being owned by a player,
* and the needed functions to take and give resources to it.
*
* @author Leonardo Brandenberger
*/
public class Bank {
private final HashMap<Config.Resource, Integer> resources = new HashMap<>();
/**
* Construct a Bank Object and stores Config Values in own HashMap.
*/
public Bank() {
resources.putAll(Config.INITIAL_RESOURCE_CARDS_BANK);
}
/**
* Stores a desired resource in desired quantity in the bank.
*
* @param resource the resource type that gets added to the bank
* @param numberOfResources the quantity of resources of the chosen type get added
*/
public void storeResourceToBank(Config.Resource resource, int numberOfResources) {
resources.put(resource, resources.get(resource) + numberOfResources);
}
/**
* Checks if a Resource is available in the quantity desired. and then deducts it from the bank inventory.
*
* @param resource the resource type that has to be deducted
* @param numberOfResources the quantity of the resource that gets deducted from the inventory
* @return true if resources available and deducted false if not enough resources are in the 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;
}
}
}