completed handleDiceThrow7 in Player.java
This commit is contained in:
		
							parent
							
								
									6bd4f1dcbe
								
							
						
					
					
						commit
						7752d6ff7e
					
				| 
						 | 
					@ -1,8 +1,6 @@
 | 
				
			||||||
package ch.zhaw.catan;
 | 
					package ch.zhaw.catan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.*;
 | 
				
			||||||
import java.util.HashMap;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * New Class PLayer
 | 
					 * New Class PLayer
 | 
				
			||||||
| 
						 | 
					@ -26,9 +24,9 @@ public class Player {
 | 
				
			||||||
        for(Config.Resource resource : Config.Resource.values()) {
 | 
					        for(Config.Resource resource : Config.Resource.values()) {
 | 
				
			||||||
            resources.put(resource,0);
 | 
					            resources.put(resource,0);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This method returns all the resources the player has at the moment
 | 
					     * This method returns all the resources the player has at the moment
 | 
				
			||||||
     * @return HashMap with the count of every resource
 | 
					     * @return HashMap with the count of every resource
 | 
				
			||||||
| 
						 | 
					@ -146,15 +144,19 @@ public class Player {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void handleDiceThrow7() {
 | 
					    public void handleDiceThrow7(Bank bank) {
 | 
				
			||||||
        int countResources = 0;
 | 
					        ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
 | 
				
			||||||
        for(Config.Resource resource : resources.keySet()){
 | 
					        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){
 | 
					        if(resourceArrayList.size() > 7){
 | 
				
			||||||
            int newCountResources = countResources / 2;
 | 
					            int resourcesToRemove =resourceArrayList.size() - (resourceArrayList.size() / 2);
 | 
				
			||||||
            ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
 | 
					            Random random = new Random();
 | 
				
			||||||
            //for(Resource resource : ) todo complete
 | 
					            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) {
 | 
					    public Map<Faction, List<Resource>> throwDice(int dicethrow) {
 | 
				
			||||||
        if (dicethrow == 7) {
 | 
					        if (dicethrow == 7) {
 | 
				
			||||||
            for(Player player : allPlayers) {
 | 
					            for(Player player : allPlayers) {
 | 
				
			||||||
                player.handleDiceThrow7();
 | 
					                player.handleDiceThrow7(bank);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            Map<Faction,List<Resource>> returnMap= new HashMap<>();
 | 
					            Map<Faction,List<Resource>> returnMap= new HashMap<>();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue