completed handleDiceThrow7 in Player.java

This commit is contained in:
schrom01 2021-12-04 17:44:15 +01:00
parent 6bd4f1dcbe
commit 7752d6ff7e
2 changed files with 14 additions and 12 deletions

View File

@ -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<Config.Resource> 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<Config.Resource> 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);
}
}
}

View File

@ -204,7 +204,7 @@ public class SiedlerGame {
public Map<Faction, List<Resource>> throwDice(int dicethrow) {
if (dicethrow == 7) {
for(Player player : allPlayers) {
player.handleDiceThrow7();
player.handleDiceThrow7(bank);
}
} else {
Map<Faction,List<Resource>> returnMap= new HashMap<>();