From 2f9f93d8623079f64bfc1f7af285cf0a77f2c90b Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Sat, 27 Nov 2021 01:45:14 +0100 Subject: [PATCH] =?UTF-8?q?Bank=20Klasse=20erstellt=20(wird=20warscheinlic?= =?UTF-8?q?h=20wieder=20entfernt=20da=20Funktionalit=C3=A4t=20in=20Siedler?= =?UTF-8?q?Game=20sein=20soll)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch/zhaw/catan/Bank.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/ch/zhaw/catan/Bank.java 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; + } + } +}