From 7752d6ff7e5b76f23ca913ce852421626a8b6414 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 4 Dec 2021 17:44:15 +0100 Subject: [PATCH] completed handleDiceThrow7 in Player.java --- src/ch/zhaw/catan/Player.java | 24 +++++++++++++----------- src/ch/zhaw/catan/SiedlerGame.java | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ch/zhaw/catan/Player.java b/src/ch/zhaw/catan/Player.java index c53847d..79f6e29 100644 --- a/src/ch/zhaw/catan/Player.java +++ b/src/ch/zhaw/catan/Player.java @@ -1,8 +1,6 @@ package ch.zhaw.catan; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; /** * New Class PLayer @@ -26,9 +24,9 @@ public class Player { for(Config.Resource resource : Config.Resource.values()) { resources.put(resource,0); } - } + /** * This method returns all the resources the player has at the moment * @return HashMap with the count of every resource @@ -146,15 +144,19 @@ public class Player { return true; } - public void handleDiceThrow7() { - int countResources = 0; + public void handleDiceThrow7(Bank bank) { + ArrayList resourceArrayList = new ArrayList<>(); for(Config.Resource resource : resources.keySet()){ - countResources += resources.get(resource); + for(int i = 0; i < resources.get(resource); i++) { + resourceArrayList.add(resource); + } } - if(countResources > 7){ - int newCountResources = countResources / 2; - ArrayList resourceArrayList = new ArrayList<>(); - //for(Resource resource : ) todo complete + if(resourceArrayList.size() > 7){ + int resourcesToRemove =resourceArrayList.size() - (resourceArrayList.size() / 2); + Random random = new Random(); + for(int i = 0; i < resourcesToRemove; i++){ + substractResource(resourceArrayList.remove(random.nextInt(resourceArrayList.size())), 1, bank); + } } } diff --git a/src/ch/zhaw/catan/SiedlerGame.java b/src/ch/zhaw/catan/SiedlerGame.java index 885710e..07f69ee 100644 --- a/src/ch/zhaw/catan/SiedlerGame.java +++ b/src/ch/zhaw/catan/SiedlerGame.java @@ -204,7 +204,7 @@ public class SiedlerGame { public Map> throwDice(int dicethrow) { if (dicethrow == 7) { for(Player player : allPlayers) { - player.handleDiceThrow7(); + player.handleDiceThrow7(bank); } } else { Map> returnMap= new HashMap<>();