Minor Grammar and Cameltow fixes
This commit is contained in:
		
							parent
							
								
									f3b9cd2771
								
							
						
					
					
						commit
						ffc97a39ef
					
				| 
						 | 
					@ -6,22 +6,21 @@ import java.util.HashMap;
 | 
				
			||||||
public class Bank {
 | 
					public class Bank {
 | 
				
			||||||
    private final HashMap<Config.Resource, Integer> resources = new HashMap<>();
 | 
					    private final HashMap<Config.Resource, Integer> resources = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Bank(){
 | 
					    public Bank() {
 | 
				
			||||||
        resources.putAll(Config.INITIAL_RESOURCE_CARDS_BANK);
 | 
					        resources.putAll(Config.INITIAL_RESOURCE_CARDS_BANK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void storeResourceToBank(Config.Resource resource, int numberOfResources) {
 | 
					    public void storeResourceToBank(Config.Resource resource, int numberOfResources) {
 | 
				
			||||||
            resources.put(resource,resources.get(resource)+numberOfResources);
 | 
					        resources.put(resource, resources.get(resource) + numberOfResources);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public boolean getResourceFromBank(Config.Resource resource,int numberOfResources) {
 | 
					    public boolean getResourceFromBank(Config.Resource resource, int numberOfResources) {
 | 
				
			||||||
        if(resources.get(resource) >= numberOfResources) {
 | 
					        if (resources.get(resource) >= numberOfResources) {
 | 
				
			||||||
            Integer newResourceNumber = resources.get(resource) - numberOfResources;
 | 
					            Integer newResourceNumber = resources.get(resource) - numberOfResources;
 | 
				
			||||||
            resources.put(resource, newResourceNumber);
 | 
					            resources.put(resource, newResourceNumber);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ import java.awt.Point;
 | 
				
			||||||
public class City extends Settlement {
 | 
					public class City extends Settlement {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public City(Config.Faction faction, Point position) {
 | 
					    public City(Config.Faction faction, Point position) {
 | 
				
			||||||
        super(faction,position);
 | 
					        super(faction, position);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String toString() {
 | 
					    public String toString() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,17 +2,16 @@ package ch.zhaw.catan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//TODO:JavaDoc
 | 
					//TODO:JavaDoc
 | 
				
			||||||
public enum Command {
 | 
					public enum Command {
 | 
				
			||||||
    NEXTPLAYER ("next player"), BUILDSETTLEMENT ("build settlement"), BUILDCITY("build city"),
 | 
					    NEXTPLAYER("next player"), BUILDSETTLEMENT("build settlement"), BUILDCITY("build city"),
 | 
				
			||||||
    BUILDROAD("build road"), TRADEWITHBANK("trade with bank"),QUIT("quit");
 | 
					    BUILDROAD("build road"), TRADEWITHBANK("trade with bank"), QUIT("quit");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final String commandWord;
 | 
					    private final String commandWord;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Command(String commandWord) {
 | 
					    Command(String commandWord) {
 | 
				
			||||||
        this.commandWord = commandWord;
 | 
					        this.commandWord = commandWord;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String toString() {
 | 
					    public String toString() {
 | 
				
			||||||
        return commandWord;
 | 
					        return commandWord;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,12 +7,12 @@ public class Field {
 | 
				
			||||||
    private Config.Land land;
 | 
					    private Config.Land land;
 | 
				
			||||||
    private final Label label;
 | 
					    private final Label label;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Field(Config.Land land, Label label){
 | 
					    public Field(Config.Land land, Label label) {
 | 
				
			||||||
        this.land = land;
 | 
					        this.land = land;
 | 
				
			||||||
        this.label = label;
 | 
					        this.label = label;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Config.Resource getResource(){
 | 
					    public Config.Resource getResource() {
 | 
				
			||||||
        return land.getResource();
 | 
					        return land.getResource();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,8 @@ package ch.zhaw.catan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
//TODO Java Doc bearbeiten
 | 
					//TODO Java Doc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * New Class PLayer
 | 
					 * New Class PLayer
 | 
				
			||||||
 * This class is here in order to maintain the resources of the players, the amount of structures that they can build,
 | 
					 * This class is here in order to maintain the resources of the players, the amount of structures that they can build,
 | 
				
			||||||
| 
						 | 
					@ -20,14 +21,14 @@ public class Player {
 | 
				
			||||||
     * @param faction this is the faction of the player.
 | 
					     * @param faction this is the faction of the player.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public Player(Config.Faction faction) {
 | 
					    public Player(Config.Faction faction) {
 | 
				
			||||||
        //Datafields
 | 
					        //Data fields
 | 
				
			||||||
        this.faction = faction;
 | 
					        this.faction = faction;
 | 
				
			||||||
        //Available Structures initialize
 | 
					        //Initialize available structures
 | 
				
			||||||
        structureToUse = new HashMap<>();
 | 
					        structureToUse = new HashMap<>();
 | 
				
			||||||
        structureToUse.put(Config.Structure.ROAD, Config.Structure.ROAD.getStockPerPlayer());
 | 
					        structureToUse.put(Config.Structure.ROAD, Config.Structure.ROAD.getStockPerPlayer());
 | 
				
			||||||
        structureToUse.put(Config.Structure.SETTLEMENT, Config.Structure.SETTLEMENT.getStockPerPlayer());
 | 
					        structureToUse.put(Config.Structure.SETTLEMENT, Config.Structure.SETTLEMENT.getStockPerPlayer());
 | 
				
			||||||
        structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer());
 | 
					        structureToUse.put(Config.Structure.CITY, Config.Structure.CITY.getStockPerPlayer());
 | 
				
			||||||
        //Resources initialize
 | 
					        //Initialize resources
 | 
				
			||||||
        resources = new HashMap<>();
 | 
					        resources = new HashMap<>();
 | 
				
			||||||
        for (Config.Resource resource : Config.Resource.values()) {
 | 
					        for (Config.Resource resource : Config.Resource.values()) {
 | 
				
			||||||
            resources.put(resource, 0);
 | 
					            resources.put(resource, 0);
 | 
				
			||||||
| 
						 | 
					@ -73,18 +74,18 @@ public class Player {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This method substracts a specific resource from resourcess but check first if player has enough resources.
 | 
					     * This method subtracts a specific resource from the player's resources. but check first if player has the specific resources.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param resource          to substract
 | 
					     * @param resource         to subtract
 | 
				
			||||||
     * @param numberToSubstract how much to substract
 | 
					     * @param numberToSubtract how much to subtract
 | 
				
			||||||
     * @return true if resource has been substracted false if player has not enough resources
 | 
					     * @return true if resource has been subtracted false if player has not enough resources
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean substractResource(Config.Resource resource, int numberToSubstract) {
 | 
					    public boolean subtractResource(Config.Resource resource, int numberToSubtract) {
 | 
				
			||||||
        int inPossesion = resources.get(resource);
 | 
					        int inPossession = resources.get(resource);
 | 
				
			||||||
        if (inPossesion - numberToSubstract < 0) {
 | 
					        if (inPossession - numberToSubtract < 0) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        resources.put(resource, inPossesion - numberToSubstract);
 | 
					        resources.put(resource, inPossession - numberToSubtract);
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -93,6 +94,7 @@ public class Player {
 | 
				
			||||||
     * and resources to build one more. If the player is able to build, this method subtracts the building cost from the resources
 | 
					     * and resources to build one more. If the player is able to build, this method subtracts the building cost from the resources
 | 
				
			||||||
     * in possession by the player.
 | 
					     * in possession by the player.
 | 
				
			||||||
     * It reduces the amount of the specific structure a player can build by 1.
 | 
					     * It reduces the amount of the specific structure a player can build by 1.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @return true if the structure can be created false if the structure can't be created.
 | 
					     * @return true if the structure can be created false if the structure can't be created.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean build(Config.Structure structure) {
 | 
					    public boolean build(Config.Structure structure) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,13 +1,14 @@
 | 
				
			||||||
package ch.zhaw.catan;
 | 
					package ch.zhaw.catan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.Point;
 | 
					import java.awt.*;
 | 
				
			||||||
/// TODO: 09/12/2021 Java Doc 
 | 
					
 | 
				
			||||||
 | 
					/// TODO: 09/12/2021 Java Doc
 | 
				
			||||||
public class Road extends Structure {
 | 
					public class Road extends Structure {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final Point start,end;
 | 
					    private final Point start, end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Road(Config.Faction faction,Point start,Point end) {
 | 
					    public Road(Config.Faction faction, Point start, Point end) {
 | 
				
			||||||
        super(faction);
 | 
					        super(faction);
 | 
				
			||||||
        this.start = start;
 | 
					        this.start = start;
 | 
				
			||||||
        this.end = end;
 | 
					        this.end = end;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,13 @@
 | 
				
			||||||
package ch.zhaw.catan;
 | 
					package ch.zhaw.catan;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.Point;
 | 
					import java.awt.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//TODO Java Doc
 | 
					//TODO Java Doc
 | 
				
			||||||
public class Settlement extends Structure {
 | 
					public class Settlement extends Structure {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Point position;
 | 
					    private Point position;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Settlement(Config.Faction faction,Point position) {
 | 
					    public Settlement(Config.Faction faction, Point position) {
 | 
				
			||||||
        super(faction);
 | 
					        super(faction);
 | 
				
			||||||
        this.position = position;
 | 
					        this.position = position;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,6 +9,7 @@ import java.util.Random;
 | 
				
			||||||
public class Siedler {
 | 
					public class Siedler {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The main Method of the game. It creates a Parser Object and calls the Methods foundingPhase (to create a new Game) and gamePhase
 | 
					     * The main Method of the game. It creates a Parser Object and calls the Methods foundingPhase (to create a new Game) and gamePhase
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param args There are no arguments needed.
 | 
					     * @param args There are no arguments needed.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static void main(String[] args) {
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
| 
						 | 
					@ -19,24 +20,25 @@ public class Siedler {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The Method for the usual game Process. It contains the Main loop to get new commands from the players and calls the associated methods.
 | 
					     * The Method for the usual game Process. It contains the Main loop to get new commands from the players and calls the associated methods.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param parser The Parser Object which will interact with the player.
 | 
					     * @param parser The Parser Object which will interact with the player.
 | 
				
			||||||
     * @param game The Game object which is already created and has the founding phase completed.
 | 
					     * @param game   The Game object which is already created and has the founding phase completed.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static void gamePhase(Parser parser, SiedlerGame game) {
 | 
					    private static void gamePhase(Parser parser, SiedlerGame game) {
 | 
				
			||||||
        boolean running = true;
 | 
					        boolean running = true;
 | 
				
			||||||
        boolean diceThrown = false;
 | 
					        boolean diceThrown = false;
 | 
				
			||||||
        while (running){
 | 
					        while (running) {
 | 
				
			||||||
            Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
 | 
					            Config.Faction currentPlayerFaction = game.getCurrentPlayerFaction();
 | 
				
			||||||
            parser.displayGameboard(game.getBoard().getTextView()); //todo jedesmal ausgeben? oder nur wenn neuer Spieler oder separater Befehl?
 | 
					            parser.displayGameboard(game.getBoard().getTextView()); //todo jedesmal ausgeben? oder nur wenn neuer Spieler oder separater Befehl?
 | 
				
			||||||
            parser.playerTurn(currentPlayerFaction);
 | 
					            parser.playerTurn(currentPlayerFaction);
 | 
				
			||||||
            if(!diceThrown) {
 | 
					            if (!diceThrown) {
 | 
				
			||||||
                throwDice(parser, game);
 | 
					                throwDice(parser, game);
 | 
				
			||||||
                diceThrown = true;
 | 
					                diceThrown = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinPoints());
 | 
					            parser.displayPlayerInfo(game.getCurrentPlayerResource(), game.getCurrentPlayerWinPoints());
 | 
				
			||||||
            switch (parser.getAction()) {
 | 
					            switch (parser.getAction()) {
 | 
				
			||||||
                case NEXTPLAYER:
 | 
					                case NEXTPLAYER:
 | 
				
			||||||
                    if(caseNextPlayer(parser, game)){
 | 
					                    if (caseNextPlayer(parser, game)) {
 | 
				
			||||||
                        running = false;
 | 
					                        running = false;
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                        diceThrown = false;
 | 
					                        diceThrown = false;
 | 
				
			||||||
| 
						 | 
					@ -66,13 +68,14 @@ public class Siedler {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The Method which is called if the player chooses the command "next Player".
 | 
					     * The Method which is called if the player chooses the command "next Player".
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param parser The parser Object which will interact with the player.
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
     * @param game The game Object which will be used to execute the Method.
 | 
					     * @param game   The game Object which will be used to execute the Method.
 | 
				
			||||||
     * @return true: if there is a winner and game is finished. false: if there is no winner (yet).
 | 
					     * @return true: if there is a winner and game is finished. false: if there is no winner (yet).
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static boolean caseNextPlayer(Parser parser, SiedlerGame game){
 | 
					    private static boolean caseNextPlayer(Parser parser, SiedlerGame game) {
 | 
				
			||||||
        Config.Faction winner = game.getWinner();
 | 
					        Config.Faction winner = game.getWinner();
 | 
				
			||||||
        if(winner == null) {
 | 
					        if (winner == null) {
 | 
				
			||||||
            game.switchToNextPlayer();
 | 
					            game.switchToNextPlayer();
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
| 
						 | 
					@ -83,42 +86,45 @@ public class Siedler {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The Method which is called if the player chooses the command "Trade with bank".
 | 
					     * The Method which is called if the player chooses the command "Trade with bank".
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param parser The parser Object which will interact with the player.
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
     * @param game The game Object which will be used to execute the Method.
 | 
					     * @param game   The game Object which will be used to execute the Method.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static void caseTradeWithBank(Parser parser, SiedlerGame game) {
 | 
					    private static void caseTradeWithBank(Parser parser, SiedlerGame game) {
 | 
				
			||||||
        Config.Resource offer = parser.trade(true);
 | 
					        Config.Resource offer = parser.trade(true);
 | 
				
			||||||
        Config.Resource want = parser.trade(false);
 | 
					        Config.Resource want = parser.trade(false);
 | 
				
			||||||
        if(!game.tradeWithBankFourToOne(offer, want)){
 | 
					        if (!game.tradeWithBankFourToOne(offer, want)) {
 | 
				
			||||||
            parser.errorMessage();
 | 
					            parser.errorMessage();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The Method which is called if the player chooses a command to build any structure.
 | 
					     * The Method which is called if the player chooses a command to build any structure.
 | 
				
			||||||
     * @param parser The parser Object which will interact with the player.
 | 
					     *
 | 
				
			||||||
     * @param game The game Object which will be used to execute the Method.
 | 
					     * @param parser    The parser Object which will interact with the player.
 | 
				
			||||||
 | 
					     * @param game      The game Object which will be used to execute the Method.
 | 
				
			||||||
     * @param structure The kind of Structure the player selected to build.
 | 
					     * @param structure The kind of Structure the player selected to build.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static void caseBuildStructure(Parser parser, SiedlerGame game, Config.Structure structure) {
 | 
					    private static void caseBuildStructure(Parser parser, SiedlerGame game, Config.Structure structure) {
 | 
				
			||||||
        parser.giveCoordinatesForStructures(structure);
 | 
					        parser.giveCoordinatesForStructures(structure);
 | 
				
			||||||
        boolean successfully = false;
 | 
					        boolean successfully = false;
 | 
				
			||||||
        if(structure == Config.Structure.SETTLEMENT){
 | 
					        if (structure == Config.Structure.SETTLEMENT) {
 | 
				
			||||||
            successfully = game.buildSettlement(parser.getPoint());
 | 
					            successfully = game.buildSettlement(parser.getPoint());
 | 
				
			||||||
        } else if(structure == Config.Structure.CITY) {
 | 
					        } else if (structure == Config.Structure.CITY) {
 | 
				
			||||||
            successfully = game.buildCity(parser.getPoint());
 | 
					            successfully = game.buildCity(parser.getPoint());
 | 
				
			||||||
        } else if(structure == Config.Structure.ROAD){
 | 
					        } else if (structure == Config.Structure.ROAD) {
 | 
				
			||||||
            successfully = game.buildRoad(parser.getPoint(), parser.getPoint());
 | 
					            successfully = game.buildRoad(parser.getPoint(), parser.getPoint());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if(!successfully){
 | 
					        if (!successfully) {
 | 
				
			||||||
            parser.errorMessage();
 | 
					            parser.errorMessage();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The method which calculates a random dice number and calls the method throwDice in the game Object.
 | 
					     * The method which calculates a random dice number and calls the method throwDice in the game Object.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param parser The parser Object which will interact with the player.
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
     * @param game The game Object which will be used to execute the Method.
 | 
					     * @param game   The game Object which will be used to execute the Method.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static void throwDice(Parser parser, SiedlerGame game) {
 | 
					    private static void throwDice(Parser parser, SiedlerGame game) {
 | 
				
			||||||
        Random random = new Random();
 | 
					        Random random = new Random();
 | 
				
			||||||
| 
						 | 
					@ -130,6 +136,7 @@ public class Siedler {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The Method which executes the whole founding phase. It Creates a new SiedlerGame Object and prompts the players to build their first structures.
 | 
					     * The Method which executes the whole founding phase. It Creates a new SiedlerGame Object and prompts the players to build their first structures.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param parser The parser Object which will interact with the player.
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
     * @return The new SiedlerGame Object which is created.
 | 
					     * @return The new SiedlerGame Object which is created.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					@ -138,15 +145,15 @@ public class Siedler {
 | 
				
			||||||
        SiedlerGame game = new SiedlerGame(gameInfo.get("NumberOfWinPoints"), gameInfo.get("NumberOfPlayers"));
 | 
					        SiedlerGame game = new SiedlerGame(gameInfo.get("NumberOfWinPoints"), gameInfo.get("NumberOfPlayers"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //each Player builds their first Settlement and first Road in reverse order than in the rest of the game
 | 
					        //each Player builds their first Settlement and first Road in reverse order than in the rest of the game
 | 
				
			||||||
        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
					        for (int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++) {
 | 
				
			||||||
            buildStructuresInFoundingPhase(parser, game, false);
 | 
					            buildStructuresInFoundingPhase(parser, game, false);
 | 
				
			||||||
            if(player < gameInfo.get("NumberOfPlayers")){
 | 
					            if (player < gameInfo.get("NumberOfPlayers")) {
 | 
				
			||||||
                game.switchToPreviousPlayer();
 | 
					                game.switchToPreviousPlayer();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //each Player builds their second Settlement and second Road and gets a Payout for these Structures in usual order.
 | 
					        //each Player builds their second Settlement and second Road and gets a Payout for these Structures in usual order.
 | 
				
			||||||
        for(int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++){
 | 
					        for (int player = 1; player <= gameInfo.get("NumberOfPlayers"); player++) {
 | 
				
			||||||
            buildStructuresInFoundingPhase(parser, game, true);
 | 
					            buildStructuresInFoundingPhase(parser, game, true);
 | 
				
			||||||
            game.switchToNextPlayer();
 | 
					            game.switchToNextPlayer();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -155,37 +162,36 @@ public class Siedler {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * The Method is called by foundingPhase. It prompts the Player to build a Settlement and a Road.
 | 
					     * The Method is called by foundingPhase. It prompts the Player to build a Settlement and a Road.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param parser The parser Object which will interact with the player.
 | 
					     * @param parser The parser Object which will interact with the player.
 | 
				
			||||||
     * @param game The game Object which will be used to execute the Method.
 | 
					     * @param game   The game Object which will be used to execute the Method.
 | 
				
			||||||
     * @param payout true (for second Settlement in founding Phase): the Player gets a payout for the settlement. false (for first Settlement in founding Phase): The Player gets no payout.
 | 
					     * @param payout true (for second Settlement in founding Phase): the Player gets a payout for the settlement. false (for first Settlement in founding Phase): The Player gets no payout.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private static void buildStructuresInFoundingPhase(Parser parser, SiedlerGame game, Boolean payout){
 | 
					    private static void buildStructuresInFoundingPhase(Parser parser, SiedlerGame game, Boolean payout) {
 | 
				
			||||||
        parser.displayGameboard(game.getBoard().getTextView());
 | 
					        parser.displayGameboard(game.getBoard().getTextView());
 | 
				
			||||||
        parser.playerTurn(game.getCurrentPlayerFaction());
 | 
					        parser.playerTurn(game.getCurrentPlayerFaction());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //build Settlement
 | 
					        //build Settlement
 | 
				
			||||||
        parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
 | 
					        parser.giveCoordinatesForStructures(Config.Structure.SETTLEMENT);
 | 
				
			||||||
        boolean successful = false;
 | 
					        boolean successful = false;
 | 
				
			||||||
        do{
 | 
					        do {
 | 
				
			||||||
            if(game.placeInitialSettlement(parser.getPoint(), payout)) {
 | 
					            if (game.placeInitialSettlement(parser.getPoint(), payout)) {
 | 
				
			||||||
                successful = true;
 | 
					                successful = true;
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else{
 | 
					 | 
				
			||||||
                parser.errorMessage();
 | 
					                parser.errorMessage();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }  while(!successful);
 | 
					        } while (!successful);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //build Road
 | 
					        //build Road
 | 
				
			||||||
        parser.displayGameboard(game.getBoard().getTextView());
 | 
					        parser.displayGameboard(game.getBoard().getTextView());
 | 
				
			||||||
        parser.giveCoordinatesForStructures(Config.Structure.ROAD);
 | 
					        parser.giveCoordinatesForStructures(Config.Structure.ROAD);
 | 
				
			||||||
        successful = false;
 | 
					        successful = false;
 | 
				
			||||||
        do{
 | 
					        do {
 | 
				
			||||||
            if(game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
 | 
					            if (game.placeInitialRoad(parser.getPoint(), parser.getPoint())) {
 | 
				
			||||||
                successful = true;
 | 
					                successful = true;
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else{
 | 
					 | 
				
			||||||
                parser.errorMessage();
 | 
					                parser.errorMessage();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }  while(!successful);
 | 
					        } while (!successful);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,8 +5,15 @@ import ch.zhaw.hexboard.HexBoard;
 | 
				
			||||||
import ch.zhaw.hexboard.Label;
 | 
					import ch.zhaw.hexboard.Label;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.Point;
 | 
					import java.awt.Point;
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					import java.util.HashSet;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.Iterator;
 | 
				
			||||||
 | 
					import java.util.Collections;
 | 
				
			||||||
//TODO Enhance JavaDoc
 | 
					//TODO Enhance JavaDoc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Subclass of HexBoard
 | 
					 * Subclass of HexBoard
 | 
				
			||||||
 * Saves the fields which are set and handles Methods with specific Dice Numbers.
 | 
					 * Saves the fields which are set and handles Methods with specific Dice Numbers.
 | 
				
			||||||
| 
						 | 
					@ -22,21 +29,20 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
    HashMap<Point, Field> fields = new HashMap<>();
 | 
					    HashMap<Point, Field> fields = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Method to create the predefined gamefield from Config.
 | 
					     * Method to create the predefined game field from Config.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void createFixGamefield(){
 | 
					    public void createFixGameField() {
 | 
				
			||||||
        Map<Point,Land> resourcePlacement = Config.getStandardLandPlacement();
 | 
					        Map<Point, Land> resourcePlacement = Config.getStandardLandPlacement();
 | 
				
			||||||
        Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement();
 | 
					        Map<Point, Integer> dicePlacement = Config.getStandardDiceNumberPlacement();
 | 
				
			||||||
        for (Map.Entry<Point,Land> resourceField : resourcePlacement.entrySet()) {
 | 
					        for (Map.Entry<Point, Land> resourceField : resourcePlacement.entrySet()) {
 | 
				
			||||||
            addField(resourceField.getKey(),resourceField.getValue());
 | 
					            addField(resourceField.getKey(), resourceField.getValue());
 | 
				
			||||||
            if(dicePlacement.get(resourceField.getKey()) != null){
 | 
					            if (dicePlacement.get(resourceField.getKey()) != null) {
 | 
				
			||||||
                String numberAsString = dicePlacement.get(resourceField.getKey()).toString();
 | 
					                String numberAsString = dicePlacement.get(resourceField.getKey()).toString();
 | 
				
			||||||
                char[] numbersInChar = numberAsString.toCharArray();
 | 
					                char[] numbersInChar = numberAsString.toCharArray();
 | 
				
			||||||
                if (numberAsString.length() < 2) {
 | 
					                if (numberAsString.length() < 2) {
 | 
				
			||||||
                    fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label('0', numbersInChar[0])));
 | 
					                    fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label('0', numbersInChar[0])));
 | 
				
			||||||
                }
 | 
					                } else {
 | 
				
			||||||
                else {
 | 
					                    fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label(numbersInChar[0], numbersInChar[1])));
 | 
				
			||||||
                    fields.put(resourceField.getKey(), new Field(resourceField.getValue(), new Label(numbersInChar[0],numbersInChar[1])));
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -44,6 +50,7 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Method to get the DiceNumber of a specific field.
 | 
					     * Method to get the DiceNumber of a specific field.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param field Point with coordinates of the specific field
 | 
					     * @param field Point with coordinates of the specific field
 | 
				
			||||||
     * @return the DiceNumber of the field.
 | 
					     * @return the DiceNumber of the field.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					@ -53,11 +60,12 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Method to create a SiedlerBoardTextView Object set the LowerFieldLabels with theirs Dicenumber.
 | 
					     * Method to create a SiedlerBoardTextView Object set the LowerFieldLabels with theirs dice number.
 | 
				
			||||||
     * It is used to print the actual board in TextIO.
 | 
					     * It is used to print the actual board in TextIO.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @return String of actual board.
 | 
					     * @return String of actual board.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public String getTextView () {
 | 
					    public String getTextView() {
 | 
				
			||||||
        SiedlerBoardTextView view = new SiedlerBoardTextView(this);
 | 
					        SiedlerBoardTextView view = new SiedlerBoardTextView(this);
 | 
				
			||||||
        for (Map.Entry<Point, Field> field : fields.entrySet()) {
 | 
					        for (Map.Entry<Point, Field> field : fields.entrySet()) {
 | 
				
			||||||
            view.setLowerFieldLabel(field.getKey(), field.getValue().getLabel());
 | 
					            view.setLowerFieldLabel(field.getKey(), field.getValue().getLabel());
 | 
				
			||||||
| 
						 | 
					@ -73,9 +81,9 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public List<Point> getFieldsForDiceValue(int dice) {
 | 
					    public List<Point> getFieldsForDiceValue(int dice) {
 | 
				
			||||||
        ArrayList<Point> fields = new ArrayList<>();
 | 
					        ArrayList<Point> fields = new ArrayList<>();
 | 
				
			||||||
        for(Point field : this.fields.keySet()){
 | 
					        for (Point field : this.fields.keySet()) {
 | 
				
			||||||
            if(getDiceNumber(field) == dice){
 | 
					            if (getDiceNumber(field) == dice) {
 | 
				
			||||||
               fields.add(field);
 | 
					                fields.add(field);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return fields;
 | 
					        return fields;
 | 
				
			||||||
| 
						 | 
					@ -84,12 +92,12 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Method to get the Resources which are paid to a specific faction for a specific field.
 | 
					     * Method to get the Resources which are paid to a specific faction for a specific field.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param point The Point with the Coordinates of the field, which should pay resources.
 | 
					     * @param point   The Point with the Coordinates of the field, which should pay resources.
 | 
				
			||||||
     * @param faction The faction, which should get paid.
 | 
					     * @param faction The faction, which should get paid.
 | 
				
			||||||
     * @return a ArrayList with all resources, which will be paid to the specified faction.
 | 
					     * @return a ArrayList with all resources, which will be paid to the specified faction.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public ArrayList<Config.Resource> getResourcesForFaction(Point point, Config.Faction faction){
 | 
					    public ArrayList<Config.Resource> getResourcesForFaction(Point point, Config.Faction faction) {
 | 
				
			||||||
        List <Settlement> possibleSettlementField = super.getCornersOfField(point);
 | 
					        List<Settlement> possibleSettlementField = super.getCornersOfField(point);
 | 
				
			||||||
        ArrayList<Config.Resource> resourcesToPlayer = new ArrayList<>();
 | 
					        ArrayList<Config.Resource> resourcesToPlayer = new ArrayList<>();
 | 
				
			||||||
        for (Settlement settlement : possibleSettlementField) {
 | 
					        for (Settlement settlement : possibleSettlementField) {
 | 
				
			||||||
            if (settlement.getFaction() == faction) {
 | 
					            if (settlement.getFaction() == faction) {
 | 
				
			||||||
| 
						 | 
					@ -110,67 +118,67 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public List<Land> getLandsForCorner(Point corner) {
 | 
					    public List<Land> getLandsForCorner(Point corner) {
 | 
				
			||||||
        Point above = new Point(corner.x, corner.y + 2);
 | 
					        Point above = new Point(corner.x, corner.y + 2);
 | 
				
			||||||
        Point below = new Point(corner.x, corner.y -2);
 | 
					        Point below = new Point(corner.x, corner.y - 2);
 | 
				
			||||||
        Land[] lands = new Land[3];
 | 
					        Land[] lands = new Land[3];
 | 
				
			||||||
        if (hasField(above)) {
 | 
					        if (hasField(above)) {
 | 
				
			||||||
            lands[0] = getField(above);
 | 
					            lands[0] = getField(above);
 | 
				
			||||||
            lands[1] = getField(new Point(corner.x + 1, corner.y - 1));
 | 
					            lands[1] = getField(new Point(corner.x + 1, corner.y - 1));
 | 
				
			||||||
            lands[2] = getField(new Point(corner.x - 1, corner.y - 1));
 | 
					            lands[2] = getField(new Point(corner.x - 1, corner.y - 1));
 | 
				
			||||||
        }
 | 
					        } else if (hasField(below)) {
 | 
				
			||||||
        else if (hasField(below)) {
 | 
					 | 
				
			||||||
            lands[0] = getField(below);
 | 
					            lands[0] = getField(below);
 | 
				
			||||||
            lands[1] = getField(new Point(corner.x + 1, corner.y + 1));
 | 
					            lands[1] = getField(new Point(corner.x + 1, corner.y + 1));
 | 
				
			||||||
            lands[2] = getField(new Point(corner.x - 1, corner.y + 1));
 | 
					            lands[2] = getField(new Point(corner.x - 1, corner.y + 1));
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return Collections.emptyList();
 | 
					            return Collections.emptyList();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return List.of(lands);
 | 
					        return List.of(lands);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					//TODO Java Doc no return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This method checks for the player with the longest road according to the catan game rules.
 | 
					     * This method checks for the player with the longest road according to the siedler game rules.
 | 
				
			||||||
     * @return a HashMap<Faction,Integer> where faction is the player with the longest road longer according to catan game rules
 | 
					     *
 | 
				
			||||||
 | 
					     * @return a HashMap<Faction,Integer> where faction is the player with the longest road longer according to siedler game rules
 | 
				
			||||||
     * and the Integer representing the length of the road
 | 
					     * and the Integer representing the length of the road
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void getLongestRoadFaction(HashMap<Config.Faction,Integer> currentLongestRoad,List<Config.Faction> factionList) {
 | 
					    public void getLongestRoadFaction(HashMap<Config.Faction, Integer> currentLongestRoad, List<Config.Faction> factionList) {
 | 
				
			||||||
        List<Settlement> corners = getCorners();
 | 
					        List<Settlement> corners = getCorners();
 | 
				
			||||||
        HashMap<Config.Faction,Integer> players = new HashMap<>();
 | 
					        HashMap<Config.Faction, Integer> players = new HashMap<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for(Config.Faction faction : factionList) {
 | 
					        for (Config.Faction faction : factionList) {
 | 
				
			||||||
            int count = 0;
 | 
					            int count = 0;
 | 
				
			||||||
            players.put(faction,count);
 | 
					            players.put(faction, count);
 | 
				
			||||||
            for(Settlement settlement : corners){
 | 
					            for (Settlement settlement : corners) {
 | 
				
			||||||
                if(settlement.getFaction() == faction){
 | 
					                if (settlement.getFaction() == faction) {
 | 
				
			||||||
                    HashSet<Road> roads = new HashSet<>();
 | 
					                    HashSet<Road> roads = new HashSet<>();
 | 
				
			||||||
                    roads = countRoad(faction,settlement.getPosition(),roads,true);
 | 
					                    roads = countRoad(faction, settlement.getPosition(), roads, true);
 | 
				
			||||||
                    count = roads.size();
 | 
					                    count = roads.size();
 | 
				
			||||||
                    int currentCount = players.get(faction);
 | 
					                    int currentCount = players.get(faction);
 | 
				
			||||||
                    if(count > currentCount) {
 | 
					                    if (count > currentCount) {
 | 
				
			||||||
                        players.put(faction,count);
 | 
					                        players.put(faction, count);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(currentLongestRoad.size() == 0) {
 | 
					        if (currentLongestRoad.size() == 0) {
 | 
				
			||||||
            Config.Faction currentFaction = null;
 | 
					            Config.Faction currentFaction = null;
 | 
				
			||||||
            int currentRoad = 4;
 | 
					            int currentRoad = 4;
 | 
				
			||||||
            for(Config.Faction factionA : players.keySet()) {
 | 
					            for (Config.Faction factionA : players.keySet()) {
 | 
				
			||||||
                if(players.get(factionA)>currentRoad) {
 | 
					                if (players.get(factionA) > currentRoad) {
 | 
				
			||||||
                    currentFaction = factionA;
 | 
					                    currentFaction = factionA;
 | 
				
			||||||
                    currentRoad = players.get(factionA);
 | 
					                    currentRoad = players.get(factionA);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if(currentFaction != null){
 | 
					            if (currentFaction != null) {
 | 
				
			||||||
                currentLongestRoad.put(currentFaction,currentRoad);
 | 
					                currentLongestRoad.put(currentFaction, currentRoad);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }else{
 | 
					        } else {
 | 
				
			||||||
            for(Config.Faction faction : players.keySet()) {
 | 
					            for (Config.Faction faction : players.keySet()) {
 | 
				
			||||||
                for(Config.Faction faction1 : currentLongestRoad.keySet()) {
 | 
					                for (Config.Faction faction1 : currentLongestRoad.keySet()) {
 | 
				
			||||||
                    if(players.get(faction) >= 5 && players.get(faction) > currentLongestRoad.get(faction1)) {
 | 
					                    if (players.get(faction) >= 5 && players.get(faction) > currentLongestRoad.get(faction1)) {
 | 
				
			||||||
                        currentLongestRoad.remove(faction1);
 | 
					                        currentLongestRoad.remove(faction1);
 | 
				
			||||||
                        currentLongestRoad.put(faction,players.get(faction));
 | 
					                        currentLongestRoad.put(faction, players.get(faction));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -180,111 +188,101 @@ public class SiedlerBoard extends HexBoard<Land, Settlement, Road, String> {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This method is recursive and adds all roads which belongs to a specific players and stringing together to a HashSet.
 | 
					     * This method is recursive and adds all roads which belongs to a specific players and stringing together to a HashSet.
 | 
				
			||||||
     * The length of the HashSet represents the length of the longest Road the player has.
 | 
					     * The length of the HashSet represents the length of the longest Road the player has.
 | 
				
			||||||
     * @param faction the faction of the player to check on
 | 
					     *
 | 
				
			||||||
     * @param position there has to be a starting point to start counting. In this case it's a corner where a settlement belonging to the players faction is build on.
 | 
					     * @param faction  the faction of the player to check on
 | 
				
			||||||
     * @param roads is the hashset with all roads belong to the player which are stringing together
 | 
					     * @param position there has to be a starting point to start counting. In this case it's a corner where a settlement belonging to the player's faction is build on.
 | 
				
			||||||
     * @param add if true branches needs to be count together. (for example if it is the starting point(first time of counting)) otherwise the longest branch is beeing added to roads.
 | 
					     * @param roads    is the hashset with all roads belong to the player which are stringing together
 | 
				
			||||||
 | 
					     * @param add      if true branches needs to be count together. (for example if it is the starting point(first time of counting)) otherwise the longest branch is being added to roads.
 | 
				
			||||||
     * @return HashSet with all roads from a specific player which are string together.
 | 
					     * @return HashSet with all roads from a specific player which are string together.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private HashSet<Road> countRoad(Config.Faction faction,Point position,HashSet<Road> roads,boolean add) {
 | 
					    private HashSet<Road> countRoad(Config.Faction faction, Point position, HashSet<Road> roads, boolean add) {
 | 
				
			||||||
        List<Road> roadslist = getAdjacentEdges(position);
 | 
					        List<Road> roadsList = getAdjacentEdges(position);
 | 
				
			||||||
        if(getCorner(position) != null && getCorner(position).getFaction() != faction) {
 | 
					        if (getCorner(position) != null && getCorner(position).getFaction() != faction) {
 | 
				
			||||||
            return roads;
 | 
					            return roads;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Iterator<Road> it2 = roads.iterator();
 | 
					        for (Road roadsRoad : roads) {
 | 
				
			||||||
        while(it2.hasNext()) {
 | 
					            Iterator<Road> it3 = roadsList.iterator();
 | 
				
			||||||
            Road roadsroad = it2.next();
 | 
					            while (it3.hasNext()) {
 | 
				
			||||||
            Iterator<Road> it3 = roadslist.iterator();
 | 
					                Road roadsListRoad = it3.next();
 | 
				
			||||||
            while (it3.hasNext()){
 | 
					                if (roadsListRoad == roadsRoad || roadsListRoad.getFaction() != faction) {
 | 
				
			||||||
                Road roadslistRoad = it3.next();
 | 
					 | 
				
			||||||
                if(roadslistRoad == roadsroad || roadslistRoad.getFaction() != faction) {
 | 
					 | 
				
			||||||
                    it3.remove();
 | 
					                    it3.remove();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (roadsList.size() == 1) {
 | 
				
			||||||
        if(roadslist.size() == 1) {
 | 
					            roads.add(roadsList.get(0));
 | 
				
			||||||
            roads.add(roadslist.get(0));
 | 
					            position = getNextPoint(roadsList.get(0), position);
 | 
				
			||||||
            position = getNextPoint(roadslist.get(0),position);
 | 
					            roads = countRoad(faction, position, roads, false);
 | 
				
			||||||
            roads = countRoad(faction,position,roads,false);
 | 
					        } else if (roadsList.size() == 2) {
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if(roadslist.size() == 2) {
 | 
					 | 
				
			||||||
            HashSet<Road> listOne = (HashSet<Road>) roads.clone();
 | 
					            HashSet<Road> listOne = (HashSet<Road>) roads.clone();
 | 
				
			||||||
            HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
 | 
					            HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
 | 
				
			||||||
            listOne.add(roadslist.get(0));
 | 
					            listOne.add(roadsList.get(0));
 | 
				
			||||||
            Point positionOne = getNextPoint(roadslist.get(0),position);
 | 
					            Point positionOne = getNextPoint(roadsList.get(0), position);
 | 
				
			||||||
            listTwo.add(roadslist.get(1));
 | 
					            listTwo.add(roadsList.get(1));
 | 
				
			||||||
            Point positionTwo = getNextPoint(roadslist.get(1),position);
 | 
					            Point positionTwo = getNextPoint(roadsList.get(1), position);
 | 
				
			||||||
            listOne = countRoad(faction,positionOne,listOne,false);
 | 
					            listOne = countRoad(faction, positionOne, listOne, false);
 | 
				
			||||||
            listTwo = countRoad(faction,positionTwo,listTwo,false);
 | 
					            listTwo = countRoad(faction, positionTwo, listTwo, false);
 | 
				
			||||||
            if(add) {
 | 
					            if (add) {
 | 
				
			||||||
                for (Road road : listOne) {
 | 
					                listTwo.addAll(listOne);
 | 
				
			||||||
                    listTwo.add(road);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                roads = listTwo;
 | 
					                roads = listTwo;
 | 
				
			||||||
            }else {
 | 
					            } else {
 | 
				
			||||||
                HashSet<Road> tallest;
 | 
					                HashSet<Road> tallest;
 | 
				
			||||||
                if(listOne.size()>= listTwo.size()) {
 | 
					                if (listOne.size() >= listTwo.size()) {
 | 
				
			||||||
                    tallest = listOne;
 | 
					                    tallest = listOne;
 | 
				
			||||||
                }else{
 | 
					                } else {
 | 
				
			||||||
                    tallest = listTwo;
 | 
					                    tallest = listTwo;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                for (Road road : tallest) {
 | 
					                roads.addAll(tallest);
 | 
				
			||||||
                    roads.add(road);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        } else if (roadsList.size() == 3) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if(roadslist.size() == 3) {
 | 
					 | 
				
			||||||
            HashSet<Road> listOne = (HashSet<Road>) roads.clone();
 | 
					            HashSet<Road> listOne = (HashSet<Road>) roads.clone();
 | 
				
			||||||
            HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
 | 
					            HashSet<Road> listTwo = (HashSet<Road>) roads.clone();
 | 
				
			||||||
            HashSet<Road> listThree = (HashSet<Road>) roads.clone();
 | 
					            HashSet<Road> listThree = (HashSet<Road>) roads.clone();
 | 
				
			||||||
            listOne.add(roadslist.get(0));
 | 
					            listOne.add(roadsList.get(0));
 | 
				
			||||||
            Point positionOne = getNextPoint(roadslist.get(0),position);
 | 
					            Point positionOne = getNextPoint(roadsList.get(0), position);
 | 
				
			||||||
            listTwo.add(roadslist.get(1));
 | 
					            listTwo.add(roadsList.get(1));
 | 
				
			||||||
            Point positionTwo = getNextPoint(roadslist.get(1),position);
 | 
					            Point positionTwo = getNextPoint(roadsList.get(1), position);
 | 
				
			||||||
            listThree.add(roadslist.get(2));
 | 
					            listThree.add(roadsList.get(2));
 | 
				
			||||||
            Point positionThree = getNextPoint(roadslist.get(2),position);
 | 
					            Point positionThree = getNextPoint(roadsList.get(2), position);
 | 
				
			||||||
            listOne = countRoad(faction,positionOne,listOne,false);
 | 
					            listOne = countRoad(faction, positionOne, listOne, false);
 | 
				
			||||||
            listTwo = countRoad(faction,positionTwo,listTwo,false);
 | 
					            listTwo = countRoad(faction, positionTwo, listTwo, false);
 | 
				
			||||||
            listThree = countRoad(faction,positionThree,listThree,false);
 | 
					            listThree = countRoad(faction, positionThree, listThree, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            HashSet<Road> tallest;
 | 
					            HashSet<Road> tallest;
 | 
				
			||||||
            HashSet<Road> secondtallest;
 | 
					            HashSet<Road> secondTallest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(listOne.size()>=listTwo.size()) {
 | 
					            if (listOne.size() >= listTwo.size()) {
 | 
				
			||||||
                tallest = listOne;
 | 
					                tallest = listOne;
 | 
				
			||||||
                secondtallest = listTwo;
 | 
					                secondTallest = listTwo;
 | 
				
			||||||
            }else {
 | 
					            } else {
 | 
				
			||||||
                tallest = listTwo;
 | 
					                tallest = listTwo;
 | 
				
			||||||
                secondtallest = listOne;
 | 
					                secondTallest = listOne;
 | 
				
			||||||
            }if(listThree.size() >= secondtallest.size()) {
 | 
					 | 
				
			||||||
                secondtallest = listThree;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            for(Road road : secondtallest) {
 | 
					            if (listThree.size() >= secondTallest.size()) {
 | 
				
			||||||
                tallest.add(road);
 | 
					                secondTallest = listThree;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            tallest.addAll(secondTallest);
 | 
				
			||||||
            roads = tallest;
 | 
					            roads = tallest;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return roads;
 | 
					        return roads;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This method is beeing used to evaluate the next starting position to get the adjacent Roads from it.
 | 
					     * This method is being used to evaluate the next starting position to get the adjacent Roads from it.
 | 
				
			||||||
     * @param road the next road to check on
 | 
					     *
 | 
				
			||||||
 | 
					     * @param road     the next road to check on
 | 
				
			||||||
     * @param position the current starting point
 | 
					     * @param position the current starting point
 | 
				
			||||||
     * @return return the oposite point of the current point.
 | 
					     * @return return the opposite point of the current point.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private Point getNextPoint(Road road,Point position) {
 | 
					    private Point getNextPoint(Road road, Point position) {
 | 
				
			||||||
        Point start = road.getStart();
 | 
					        Point start = road.getStart();
 | 
				
			||||||
        Point end = road.getEnd();
 | 
					        Point end = road.getEnd();
 | 
				
			||||||
        if(position.equals(start)) {
 | 
					        if (position.equals(start)) {
 | 
				
			||||||
            position = end;
 | 
					            position = end;
 | 
				
			||||||
        }else {
 | 
					        } else {
 | 
				
			||||||
            position = start;
 | 
					            position = start;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return position;
 | 
					        return position;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,8 +9,6 @@ import java.util.HashMap;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Random;
 | 
					import java.util.Random;
 | 
				
			||||||
import java.util.Iterator;
 | 
					 | 
				
			||||||
import java.util.HashSet;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -29,7 +27,7 @@ public class SiedlerGame {
 | 
				
			||||||
    private final int winPointsForWin;
 | 
					    private final int winPointsForWin;
 | 
				
			||||||
    private final Bank bank;
 | 
					    private final Bank bank;
 | 
				
			||||||
    private int activePlayer;
 | 
					    private int activePlayer;
 | 
				
			||||||
    private HashMap<Config.Faction,Integer> longestRoadFaction;
 | 
					    private final HashMap<Config.Faction, Integer> longestRoadFaction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Constructs a SiedlerGame game state object.
 | 
					     * Constructs a SiedlerGame game state object.
 | 
				
			||||||
| 
						 | 
					@ -40,12 +38,12 @@ public class SiedlerGame {
 | 
				
			||||||
     *                                  three or players is not between two and four
 | 
					     *                                  three or players is not between two and four
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public SiedlerGame(int winPoints, int numberOfPlayers) {
 | 
					    public SiedlerGame(int winPoints, int numberOfPlayers) {
 | 
				
			||||||
        if(winPoints < 3 || numberOfPlayers < Config.MIN_NUMBER_OF_PLAYERS || numberOfPlayers > 4) {
 | 
					        if (winPoints < 3 || numberOfPlayers < Config.MIN_NUMBER_OF_PLAYERS || numberOfPlayers > 4) {
 | 
				
			||||||
            throw new IllegalArgumentException();
 | 
					            throw new IllegalArgumentException();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        bank = new Bank();
 | 
					        bank = new Bank();
 | 
				
			||||||
        board = new SiedlerBoard();
 | 
					        board = new SiedlerBoard();
 | 
				
			||||||
        board.createFixGamefield();
 | 
					        board.createFixGameField();
 | 
				
			||||||
        allPlayers = new ArrayList<>();
 | 
					        allPlayers = new ArrayList<>();
 | 
				
			||||||
        createPlayer(numberOfPlayers);
 | 
					        createPlayer(numberOfPlayers);
 | 
				
			||||||
        activePlayer = 0;
 | 
					        activePlayer = 0;
 | 
				
			||||||
| 
						 | 
					@ -63,10 +61,9 @@ public class SiedlerGame {
 | 
				
			||||||
     * Switches to the next player in the defined sequence of players.
 | 
					     * Switches to the next player in the defined sequence of players.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void switchToNextPlayer() {
 | 
					    public void switchToNextPlayer() {
 | 
				
			||||||
        if (activePlayer < allPlayers.size() -1){
 | 
					        if (activePlayer < allPlayers.size() - 1) {
 | 
				
			||||||
            activePlayer++;
 | 
					            activePlayer++;
 | 
				
			||||||
        }
 | 
					        } else if (activePlayer == allPlayers.size() - 1) {
 | 
				
			||||||
        else if (activePlayer == allPlayers.size() -1){
 | 
					 | 
				
			||||||
            activePlayer = 0;
 | 
					            activePlayer = 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -75,24 +72,25 @@ public class SiedlerGame {
 | 
				
			||||||
     * Switches to the previous player in the defined sequence of players.
 | 
					     * Switches to the previous player in the defined sequence of players.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void switchToPreviousPlayer() {
 | 
					    public void switchToPreviousPlayer() {
 | 
				
			||||||
        if (activePlayer > 0){
 | 
					        if (activePlayer > 0) {
 | 
				
			||||||
            activePlayer--;
 | 
					            activePlayer--;
 | 
				
			||||||
        }
 | 
					        } else if (activePlayer == 0) {
 | 
				
			||||||
        else if (activePlayer == 0){
 | 
					            activePlayer = allPlayers.size() - 1;
 | 
				
			||||||
            activePlayer = allPlayers.size()-1;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //TODO JavaDoc
 | 
					    //TODO JavaDoc
 | 
				
			||||||
    private boolean addResourcesToPlayer(Player player, Resource resource, int numberToAdd){
 | 
					    private boolean addResourcesToPlayer(Player player, Resource resource, int numberToAdd) {
 | 
				
			||||||
        if(bank.getResourceFromBank(resource, numberToAdd)){
 | 
					        if (bank.getResourceFromBank(resource, numberToAdd)) {
 | 
				
			||||||
            player.addResource(resource, numberToAdd);
 | 
					            player.addResource(resource, numberToAdd);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //TODO JavaDoc
 | 
					    //TODO JavaDoc
 | 
				
			||||||
    private boolean subtractResourceFromPlayer(Player player, Resource resource, int numberToSubtract){
 | 
					    private boolean subtractResourceFromPlayer(Player player, Resource resource, int numberToSubtract) {
 | 
				
			||||||
        if(player.substractResource(resource, numberToSubtract)){
 | 
					        if (player.subtractResource(resource, numberToSubtract)) {
 | 
				
			||||||
            bank.storeResourceToBank(resource, numberToSubtract);
 | 
					            bank.storeResourceToBank(resource, numberToSubtract);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -114,14 +112,12 @@ public class SiedlerGame {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public List<Faction> getPlayerFactions() {
 | 
					    public List<Faction> getPlayerFactions() {
 | 
				
			||||||
        List<Faction> factions = new ArrayList<>();
 | 
					        List<Faction> factions = new ArrayList<>();
 | 
				
			||||||
        for (Player player: allPlayers ) {
 | 
					        for (Player player : allPlayers) {
 | 
				
			||||||
            factions.add(player.getFaction());
 | 
					            factions.add(player.getFaction());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return factions;
 | 
					        return factions;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Returns the game board.
 | 
					     * Returns the game board.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					@ -168,11 +164,11 @@ public class SiedlerGame {
 | 
				
			||||||
     * @return true, if the placement was successful
 | 
					     * @return true, if the placement was successful
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean placeInitialSettlement(Point position, boolean payout) {
 | 
					    public boolean placeInitialSettlement(Point position, boolean payout) {
 | 
				
			||||||
        if(!validPositionForSettlement(position)){
 | 
					        if (!validPositionForSettlement(position)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction(),position));
 | 
					        board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction(), position));
 | 
				
			||||||
        if(payout) {
 | 
					        if (payout) {
 | 
				
			||||||
            List<Config.Land> lands = board.getLandsForCorner(position);
 | 
					            List<Config.Land> lands = board.getLandsForCorner(position);
 | 
				
			||||||
            for (Config.Land land : lands) {
 | 
					            for (Config.Land land : lands) {
 | 
				
			||||||
                if (land.getResource() != null) {
 | 
					                if (land.getResource() != null) {
 | 
				
			||||||
| 
						 | 
					@ -192,10 +188,10 @@ public class SiedlerGame {
 | 
				
			||||||
     * @return true, if the placement was successful
 | 
					     * @return true, if the placement was successful
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean placeInitialRoad(Point roadStart, Point roadEnd) {
 | 
					    public boolean placeInitialRoad(Point roadStart, Point roadEnd) {
 | 
				
			||||||
        if (!validPositionForRoad(roadStart, roadEnd)){
 | 
					        if (!validPositionForRoad(roadStart, roadEnd)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        board.setEdge(roadStart, roadEnd, new Road(allPlayers.get(activePlayer).getFaction(),roadStart,roadEnd));
 | 
					        board.setEdge(roadStart, roadEnd, new Road(allPlayers.get(activePlayer).getFaction(), roadStart, roadEnd));
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -222,17 +218,17 @@ 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) {
 | 
				
			||||||
                handleDiceThrow7(player);
 | 
					                handleDiceThrow7(player);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            Map<Faction,List<Resource>> returnMap= new HashMap<>();
 | 
					            Map<Faction, List<Resource>> returnMap = new HashMap<>();
 | 
				
			||||||
            List<Point> diceValueFields = board.getFieldsForDiceValue(diceThrow);
 | 
					            List<Point> diceValueFields = board.getFieldsForDiceValue(diceThrow);
 | 
				
			||||||
            for (Player player : allPlayers) {
 | 
					            for (Player player : allPlayers) {
 | 
				
			||||||
                returnMap.put(player.getFaction(), new ArrayList<>());
 | 
					                returnMap.put(player.getFaction(), new ArrayList<>());
 | 
				
			||||||
                for (Point field : diceValueFields) {
 | 
					                for (Point field : diceValueFields) {
 | 
				
			||||||
                    List<Resource> resources = board.getResourcesForFaction(field,player.getFaction());
 | 
					                    List<Resource> resources = board.getResourcesForFaction(field, player.getFaction());
 | 
				
			||||||
                    for (Config.Resource resource : resources){
 | 
					                    for (Config.Resource resource : resources) {
 | 
				
			||||||
                        returnMap.get(player.getFaction()).add(resource);
 | 
					                        returnMap.get(player.getFaction()).add(resource);
 | 
				
			||||||
                        addResourcesToPlayer(player, resource, 1);
 | 
					                        addResourcesToPlayer(player, resource, 1);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
| 
						 | 
					@ -242,26 +238,26 @@ public class SiedlerGame {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //TODO JavaDoc
 | 
					    //TODO JavaDoc
 | 
				
			||||||
    public void handleDiceThrow7(Player player) {
 | 
					    public void handleDiceThrow7(Player player) {
 | 
				
			||||||
        ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
 | 
					        ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
 | 
				
			||||||
        HashMap<Resource, Integer> resources = player.getResources();
 | 
					        HashMap<Resource, Integer> resources = player.getResources();
 | 
				
			||||||
        for(Config.Resource resource : resources.keySet()){
 | 
					        for (Config.Resource resource : resources.keySet()) {
 | 
				
			||||||
            for(int i = 0; i < resources.get(resource); i++) {
 | 
					            for (int i = 0; i < resources.get(resource); i++) {
 | 
				
			||||||
                resourceArrayList.add(resource);
 | 
					                resourceArrayList.add(resource);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if(resourceArrayList.size() > Config.MAX_CARDS_IN_HAND_NO_DROP){
 | 
					        if (resourceArrayList.size() > Config.MAX_CARDS_IN_HAND_NO_DROP) {
 | 
				
			||||||
            int resourcesToRemove =resourceArrayList.size() - (resourceArrayList.size() / 2);
 | 
					            int resourcesToRemove = resourceArrayList.size() - (resourceArrayList.size() / 2);
 | 
				
			||||||
            Random random = new Random();
 | 
					            Random random = new Random();
 | 
				
			||||||
            for(int i = 0; i < resourcesToRemove; i++){
 | 
					            for (int i = 0; i < resourcesToRemove; i++) {
 | 
				
			||||||
                subtractResourceFromPlayer(player, resourceArrayList.remove(random.nextInt(resourceArrayList.size())), 1);
 | 
					                subtractResourceFromPlayer(player, resourceArrayList.remove(random.nextInt(resourceArrayList.size())), 1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Builds a settlement at the specified position on the board.
 | 
					     * Builds a settlement at the specified position on the board.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
| 
						 | 
					@ -277,11 +273,11 @@ public class SiedlerGame {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean buildSettlement(Point position) {
 | 
					    public boolean buildSettlement(Point position) {
 | 
				
			||||||
        //1. Check if position is corner && is empty && neighbour Corners are empty
 | 
					        //1. Check if position is corner && is empty && neighbour Corners are empty
 | 
				
			||||||
        if(!validPositionForSettlement(position)) {
 | 
					        if (!validPositionForSettlement(position)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //2. Check if neighbourEdge are Roads belong to active Player
 | 
					        //2. Check if neighbourEdge are Roads belong to active Player
 | 
				
			||||||
        if(!checkAdjacentEdgesList(position)) {
 | 
					        if (!checkAdjacentEdgesList(position)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //3. Can Player build Settlement
 | 
					        //3. Can Player build Settlement
 | 
				
			||||||
| 
						 | 
					@ -295,7 +291,7 @@ public class SiedlerGame {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //4. Insert Settlement to map
 | 
					        //4. Insert Settlement to map
 | 
				
			||||||
        board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction(),position));
 | 
					        board.setCorner(position, new Settlement(allPlayers.get(activePlayer).getFaction(), position));
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -314,16 +310,16 @@ public class SiedlerGame {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean buildCity(Point position) {
 | 
					    public boolean buildCity(Point position) {
 | 
				
			||||||
        //1. Check if Corner.
 | 
					        //1. Check if Corner.
 | 
				
			||||||
        if (!board.hasCorner(position)){
 | 
					        if (!board.hasCorner(position)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //2. Check if Settlement has already been built
 | 
					        //2. Check if Settlement has already been built
 | 
				
			||||||
        Settlement atCurrentPosition = board.getCorner(position);
 | 
					        Settlement atCurrentPosition = board.getCorner(position);
 | 
				
			||||||
        if (atCurrentPosition == null || atCurrentPosition instanceof City || atCurrentPosition.getFaction() != allPlayers.get(activePlayer).getFaction()){
 | 
					        if (atCurrentPosition == null || atCurrentPosition instanceof City || atCurrentPosition.getFaction() != allPlayers.get(activePlayer).getFaction()) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //3. Can player build a City.
 | 
					        //3. Can player build a City.
 | 
				
			||||||
        if(!allPlayers.get(activePlayer).build(Config.Structure.CITY)){
 | 
					        if (!allPlayers.get(activePlayer).build(Config.Structure.CITY)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -333,7 +329,7 @@ public class SiedlerGame {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //4.Insert City into the map.
 | 
					        //4.Insert City into the map.
 | 
				
			||||||
        board.setCorner(position,new City(allPlayers.get(activePlayer).getFaction(),position));
 | 
					        board.setCorner(position, new City(allPlayers.get(activePlayer).getFaction(), position));
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -354,7 +350,7 @@ public class SiedlerGame {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean buildRoad(Point roadStart, Point roadEnd) {
 | 
					    public boolean buildRoad(Point roadStart, Point roadEnd) {
 | 
				
			||||||
        //1. Check if is edge && is empty && if neighbour Edge or Corners belong to Settlement of active Player
 | 
					        //1. Check if is edge && is empty && if neighbour Edge or Corners belong to Settlement of active Player
 | 
				
			||||||
        if (!validPositionForRoad(roadStart,roadEnd)){
 | 
					        if (!validPositionForRoad(roadStart, roadEnd)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //2. Can Player build road
 | 
					        //2. Can Player build road
 | 
				
			||||||
| 
						 | 
					@ -368,18 +364,19 @@ public class SiedlerGame {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //3. Insert Road to map
 | 
					        //3. Insert Road to map
 | 
				
			||||||
        board.setEdge(roadStart, roadEnd, new Road(allPlayers.get(activePlayer).getFaction(),roadStart,roadEnd));
 | 
					        board.setEdge(roadStart, roadEnd, new Road(allPlayers.get(activePlayer).getFaction(), roadStart, roadEnd));
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This Method is used to check if the chosen position for a road is valid or not.
 | 
					     * This Method is used to check if the chosen position for a road is valid or not.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param roadStart the coordinates where the road begins.
 | 
					     * @param roadStart the coordinates where the road begins.
 | 
				
			||||||
     * @param roadEnd the coordinates where the road ends.
 | 
					     * @param roadEnd   the coordinates where the road ends.
 | 
				
			||||||
     * @return true if road position is valid otherwise false
 | 
					     * @return true if road position is valid otherwise false
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean validPositionForRoad(Point roadStart, Point roadEnd){
 | 
					    private boolean validPositionForRoad(Point roadStart, Point roadEnd) {
 | 
				
			||||||
        //1. Check if it is an edge
 | 
					        //1. Check if it is an edge
 | 
				
			||||||
        if (!board.hasEdge(roadStart, roadEnd)) {
 | 
					        if (!board.hasEdge(roadStart, roadEnd)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
| 
						 | 
					@ -390,7 +387,7 @@ public class SiedlerGame {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //3. Check if neighbouring edges are roads
 | 
					        //3. Check if neighbouring edges are roads
 | 
				
			||||||
        boolean hasNeighbourRoad = (checkAdjacentEdgesList(roadStart) || checkAdjacentEdgesList(roadEnd));
 | 
					        boolean hasNeighbourRoad = (checkAdjacentEdgesList(roadStart) || checkAdjacentEdgesList(roadEnd));
 | 
				
			||||||
        if(hasNeighbourRoad) {
 | 
					        if (hasNeighbourRoad) {
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //4.Check if roadStart or roadEnd is Settlement of current player
 | 
					        //4.Check if roadStart or roadEnd is Settlement of current player
 | 
				
			||||||
| 
						 | 
					@ -400,20 +397,21 @@ public class SiedlerGame {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Can be used for both initial Settlement and normal Phase.
 | 
					     * Can be used for both initial Settlement and normal Phase.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param position the position on the board to check for valid settlement position
 | 
					     * @param position the position on the board to check for valid settlement position
 | 
				
			||||||
     * @return true if valid position for settlement
 | 
					     * @return true if valid position for settlement
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean validPositionForSettlement(Point position){
 | 
					    private boolean validPositionForSettlement(Point position) {
 | 
				
			||||||
        //1. Check if corner
 | 
					        //1. Check if corner
 | 
				
			||||||
        if (!board.hasCorner(position)) {
 | 
					        if (!board.hasCorner(position)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //2. Check if water
 | 
					        //2. Check if water
 | 
				
			||||||
        if(checkIfWater(position)) {
 | 
					        if (checkIfWater(position)) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //3. Check if corner is empty
 | 
					        //3. Check if corner is empty
 | 
				
			||||||
        if(board.getCorner(position) != null) {
 | 
					        if (board.getCorner(position) != null) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //3. Check if neighbouring corners are empty
 | 
					        //3. Check if neighbouring corners are empty
 | 
				
			||||||
| 
						 | 
					@ -422,8 +420,8 @@ public class SiedlerGame {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private boolean checkIfWater(Point point) {
 | 
					    private boolean checkIfWater(Point point) {
 | 
				
			||||||
        List<Config.Land> fields = board.getFields(point);
 | 
					        List<Config.Land> fields = board.getFields(point);
 | 
				
			||||||
        for(Config.Land land : fields) {
 | 
					        for (Config.Land land : fields) {
 | 
				
			||||||
            if(!land.equals(Config.Land.WATER)) {
 | 
					            if (!land.equals(Config.Land.WATER)) {
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -432,6 +430,7 @@ public class SiedlerGame {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * This method checks if there are Roads build by active Player on adjacent edges
 | 
					     * This method checks if there are Roads build by active Player on adjacent edges
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param point point to check on
 | 
					     * @param point point to check on
 | 
				
			||||||
     * @return true if there is a road build next to the point.
 | 
					     * @return true if there is a road build next to the point.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					@ -447,6 +446,7 @@ public class SiedlerGame {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Checks if Adjacent Corners are empty
 | 
					     * Checks if Adjacent Corners are empty
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
     * @param point Corner to check
 | 
					     * @param point Corner to check
 | 
				
			||||||
     * @return true if all Neighbour Corners are emtpy
 | 
					     * @return true if all Neighbour Corners are emtpy
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					@ -468,7 +468,7 @@ public class SiedlerGame {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public boolean tradeWithBankFourToOne(Resource offer, Resource want) {
 | 
					    public boolean tradeWithBankFourToOne(Resource offer, Resource want) {
 | 
				
			||||||
        Player player = allPlayers.get(activePlayer);
 | 
					        Player player = allPlayers.get(activePlayer);
 | 
				
			||||||
        if(player.getSpecificResource(offer) >= FOUR_TO_ONE_TRADE_OFFER && addResourcesToPlayer(player, want, FOUR_TO_ONE_TRADE_WANT)){
 | 
					        if (player.getSpecificResource(offer) >= FOUR_TO_ONE_TRADE_OFFER && addResourcesToPlayer(player, want, FOUR_TO_ONE_TRADE_WANT)) {
 | 
				
			||||||
            subtractResourceFromPlayer(player, offer, FOUR_TO_ONE_TRADE_OFFER);
 | 
					            subtractResourceFromPlayer(player, offer, FOUR_TO_ONE_TRADE_OFFER);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -480,34 +480,35 @@ public class SiedlerGame {
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return the winner of the game or null, if there is no winner (yet)
 | 
					     * @return the winner of the game or null, if there is no winner (yet)
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
        public Faction getWinner() {
 | 
					    public Faction getWinner() {
 | 
				
			||||||
            if(getCurrentPlayerWinPoints() >= winPointsForWin){
 | 
					        if (getCurrentPlayerWinPoints() >= winPointsForWin) {
 | 
				
			||||||
                return getCurrentPlayerFaction();
 | 
					            return getCurrentPlayerFaction();
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    //Todo Java Doc
 | 
					        return null;
 | 
				
			||||||
        public int getCurrentPlayerWinPoints(){
 | 
					    }
 | 
				
			||||||
            int winPoints = 0;
 | 
					 | 
				
			||||||
            List<Settlement> settlements = board.getCorners();
 | 
					 | 
				
			||||||
            for(Structure structure : settlements) {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                int newWinPoints = 0;
 | 
					    //Todo Java Doc
 | 
				
			||||||
                if(structure instanceof City){
 | 
					    public int getCurrentPlayerWinPoints() {
 | 
				
			||||||
                    newWinPoints = 2;
 | 
					        int winPoints = 0;
 | 
				
			||||||
                } else if(structure instanceof Settlement) {
 | 
					        List<Settlement> settlements = board.getCorners();
 | 
				
			||||||
                    newWinPoints = 1;
 | 
					        for (Structure structure : settlements) {
 | 
				
			||||||
                }
 | 
					
 | 
				
			||||||
                if(structure.getFaction() == getCurrentPlayerFaction()){
 | 
					            int newWinPoints = 0;
 | 
				
			||||||
                    winPoints += newWinPoints;
 | 
					            if (structure instanceof City) {
 | 
				
			||||||
                }
 | 
					                newWinPoints = 2;
 | 
				
			||||||
 | 
					            } else if (structure instanceof Settlement) {
 | 
				
			||||||
 | 
					                newWinPoints = 1;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            board.getLongestRoadFaction(longestRoadFaction,getPlayerFactions());
 | 
					            if (structure.getFaction() == getCurrentPlayerFaction()) {
 | 
				
			||||||
            if(longestRoadFaction.get(getCurrentPlayerFaction()) != null){
 | 
					                winPoints += newWinPoints;
 | 
				
			||||||
                winPoints += 2;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            return winPoints;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        board.getLongestRoadFaction(longestRoadFaction, getPlayerFactions());
 | 
				
			||||||
 | 
					        if (longestRoadFaction.get(getCurrentPlayerFaction()) != null) {
 | 
				
			||||||
 | 
					            winPoints += 2;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return winPoints;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Places the thief on the specified field and steals a random resource card (if
 | 
					     * Places the thief on the specified field and steals a random resource card (if
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,9 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
				
			||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
 | 
					import static org.junit.jupiter.api.Assertions.assertTrue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ch.zhaw.catan.games.ThreePlayerStandard;
 | 
					import ch.zhaw.catan.games.ThreePlayerStandard;
 | 
				
			||||||
import org.beryx.textio.TextIO;
 | 
					 | 
				
			||||||
import org.beryx.textio.TextIoFactory;
 | 
					 | 
				
			||||||
import org.beryx.textio.TextTerminal;
 | 
					 | 
				
			||||||
import org.junit.jupiter.api.*;
 | 
					import org.junit.jupiter.api.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.awt.*;
 | 
					import java.awt.*;
 | 
				
			||||||
| 
						 | 
					@ -45,7 +42,7 @@ public class SiedlerGameTest {
 | 
				
			||||||
            List<Config.Faction> factionList = Arrays.asList(Config.Faction.values());
 | 
					            List<Config.Faction> factionList = Arrays.asList(Config.Faction.values());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            SiedlerBoard board = new SiedlerBoard();
 | 
					            SiedlerBoard board = new SiedlerBoard();
 | 
				
			||||||
            board.createFixGamefield();
 | 
					            board.createFixGameField();
 | 
				
			||||||
            board.setEdge(new Point(6, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(6, 6),new Point(5, 7)));
 | 
					            board.setEdge(new Point(6, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(6, 6),new Point(5, 7)));
 | 
				
			||||||
            board.setEdge(new Point(4, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(5, 7)));
 | 
					            board.setEdge(new Point(4, 6), new Point(5, 7), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(5, 7)));
 | 
				
			||||||
            board.setEdge(new Point(4, 6), new Point(4, 4), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(4, 4)));
 | 
					            board.setEdge(new Point(4, 6), new Point(4, 4), new Road(Config.Faction.BLUE,new Point(4, 6),new Point(4, 4)));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue