completed handleDiceThrow7 in Player.java
This commit is contained in:
parent
6bd4f1dcbe
commit
7752d6ff7e
|
@ -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;
|
||||
for(Config.Resource resource : resources.keySet()){
|
||||
countResources += resources.get(resource);
|
||||
}
|
||||
if(countResources > 7){
|
||||
int newCountResources = countResources / 2;
|
||||
public void handleDiceThrow7(Bank bank) {
|
||||
ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
|
||||
//for(Resource resource : ) todo complete
|
||||
for(Config.Resource resource : resources.keySet()){
|
||||
for(int i = 0; i < resources.get(resource); i++) {
|
||||
resourceArrayList.add(resource);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<>();
|
||||
|
|
Loading…
Reference in New Issue