From b758e08fdb288677ae9741d31b63b2c83a40d3a5 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 7 Dec 2021 13:57:33 +0100 Subject: [PATCH] refactoring Method storeResourcesToBank --- src/ch/zhaw/catan/Bank.java | 6 ++---- src/ch/zhaw/catan/SiedlerGame.java | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/ch/zhaw/catan/Bank.java b/src/ch/zhaw/catan/Bank.java index 5b0d0a4..39e7319 100644 --- a/src/ch/zhaw/catan/Bank.java +++ b/src/ch/zhaw/catan/Bank.java @@ -12,10 +12,8 @@ public class Bank { } - public void storeResourceToBank(List resourceToGive) { - for (Config.Resource resource : resourceToGive) { - resources.put(resource,resources.get(resource)+1); - } + public void storeResourceToBank(Config.Resource resource, int numberOfResources) { + resources.put(resource,resources.get(resource)+numberOfResources); } public boolean getResourceFromBank(Config.Resource resource,int numberOfResources) { diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 24f534e..9f5c04f 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -86,11 +86,7 @@ public class SiedlerGame { private boolean substractResourceFromPlayer(Player player, Resource resource, int numberToSubstract){ if(player.substractResource(resource, numberToSubstract)){ - ArrayList resourcesForBank = new ArrayList<>(); - for(int i = 0; i < numberToSubstract; i++){ - resourcesForBank.add(resource); - } - bank.storeResourceToBank(resourcesForBank); + bank.storeResourceToBank(resource, numberToSubstract); return true; } return false;