Finished Class Bank (Cleanup and Javadoc)

This commit is contained in:
Leonardo Brandenberger 2021-12-10 09:50:47 +01:00
parent 3f625e1e47
commit 609e406d6f
1 changed files with 22 additions and 2 deletions

View File

@ -2,19 +2,39 @@ package ch.zhaw.catan;
import java.util.HashMap; 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 { public class Bank {
private final HashMap<Config.Resource, Integer> resources = new HashMap<>(); private final HashMap<Config.Resource, Integer> resources = new HashMap<>();
/**
* Construct a Bank Object and stores Config Values in own HashMap.
*/
public Bank() { public Bank() {
resources.putAll(Config.INITIAL_RESOURCE_CARDS_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) { public void storeResourceToBank(Config.Resource resource, int numberOfResources) {
resources.put(resource, resources.get(resource) + 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) { public boolean getResourceFromBank(Config.Resource resource, int numberOfResources) {
if (resources.get(resource) >= numberOfResources) { if (resources.get(resource) >= numberOfResources) {
Integer newResourceNumber = resources.get(resource) - numberOfResources; Integer newResourceNumber = resources.get(resource) - numberOfResources;