Added method buildCity.
This commit is contained in:
		
							parent
							
								
									1e49424b9c
								
							
						
					
					
						commit
						70b27af038
					
				| 
						 | 
				
			
			@ -13,6 +13,7 @@ public class Player {
 | 
			
		|||
    private HashMap<Config.Resource,Integer> resources;
 | 
			
		||||
    private int roadsToUse;
 | 
			
		||||
    private int settlementsToUse;
 | 
			
		||||
    private int citiesToUse;
 | 
			
		||||
 | 
			
		||||
    public Player (Config.Faction faction){
 | 
			
		||||
        //Datenfelder
 | 
			
		||||
| 
						 | 
				
			
			@ -91,9 +92,9 @@ public class Player {
 | 
			
		|||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method has to be used when a player wants to build a settlement. It checks if a player has enough roads
 | 
			
		||||
     * and resources to build one more. If player is able to build, the method substract the buildcost from the resources
 | 
			
		||||
     * in possesion by the player.
 | 
			
		||||
     * @return true if road can be created false if road can't be created
 | 
			
		||||
     * and resources to build one more. If the player is able to build, this method subtracts the buildcost from the resources
 | 
			
		||||
     * in possession by the player.
 | 
			
		||||
     * @return true if road can be created false if road can't be created.
 | 
			
		||||
     */
 | 
			
		||||
    public boolean buildSettlement() {
 | 
			
		||||
        List<Config.Resource> costs = Config.Structure.SETTLEMENT.getCosts();
 | 
			
		||||
| 
						 | 
				
			
			@ -106,6 +107,23 @@ public class Player {
 | 
			
		|||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method has to be used when a player wants to build a city. It checks if a player already has a settlement
 | 
			
		||||
     * on that position and if he has enough resource to build one. If the player is able to build, this method subtracts
 | 
			
		||||
     * the buildcost from the resources in possession by the player.
 | 
			
		||||
     * @return true if road can be created false if road can't be created.
 | 
			
		||||
     */
 | 
			
		||||
    public boolean buildCity() {
 | 
			
		||||
        List<Config.Resource> costs = Config.Structure.CITY.getCosts();
 | 
			
		||||
        if ( citiesToUse == 0 || !checkRessourceToBuild(costs)){
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        for (Config.Resource resource : costs){
 | 
			
		||||
            resources.put(resource,resources.get(resource)-1);
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
   //returns true if player has enough resources else false
 | 
			
		||||
    private boolean checkRessourceToBuild(List<Config.Resource> liste) {
 | 
			
		||||
        for (Config.Resource resource : liste) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -219,7 +219,7 @@ public class SiedlerGame {
 | 
			
		|||
        }
 | 
			
		||||
        //4. Insert Road to map
 | 
			
		||||
        board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction()));
 | 
			
		||||
        //5. Give Resoure to bank
 | 
			
		||||
        //5. Give Resources to bank
 | 
			
		||||
        bank.storeResourceToBank(Config.Structure.SETTLEMENT.getCosts());
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -239,6 +239,21 @@ public class SiedlerGame {
 | 
			
		|||
     */
 | 
			
		||||
    public boolean buildCity(Point position) {
 | 
			
		||||
        // TODO: OPTIONAL task - Implement
 | 
			
		||||
        //1. Check if Corner.
 | 
			
		||||
        if (!board.hasCorner(position)){
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        //2. Check if Settlement has already been built
 | 
			
		||||
        Settlement atCurrentPosition = (Settlement) board.getCorner(position);
 | 
			
		||||
 | 
			
		||||
        //3. Can player build a City.
 | 
			
		||||
        if(!allPlayers.get(activePlayer).buildCity()){
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        //4.Insert City into the map.
 | 
			
		||||
        board.setCorner(position,new City(allPlayers.get(activePlayer).getFaction()));
 | 
			
		||||
        //5. Give resources to the bank.
 | 
			
		||||
        bank.storeResourceToBank(Config.Structure.CITY.getCosts());
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue