Merge remote-tracking branch 'origin/main'
This commit is contained in:
		
						commit
						91ab0aef47
					
				| 
						 | 
				
			
			@ -2,7 +2,6 @@ package ch.zhaw.catan;
 | 
			
		|||
 | 
			
		||||
import ch.zhaw.hexboard.HexBoard;
 | 
			
		||||
import ch.zhaw.hexboard.Label;
 | 
			
		||||
 | 
			
		||||
import java.awt.Point;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,7 +24,7 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
 | 
			
		|||
     */
 | 
			
		||||
    private final HashMap<Point, Field> fields = new HashMap<>();
 | 
			
		||||
    private Config.Faction longestRoadFaction = null;
 | 
			
		||||
    private int longestRoadLenth = 0;
 | 
			
		||||
    private int longestRoadLength = 0;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to create the predefined game field from Config.
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +46,15 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get Paramter longestRoad
 | 
			
		||||
     *
 | 
			
		||||
     * @return longestRoadLength
 | 
			
		||||
     */
 | 
			
		||||
    public int getLongestRoadLength() {
 | 
			
		||||
        return longestRoadLength;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method to get the DiceNumber of a specific field.
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			@ -132,10 +140,9 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
 | 
			
		|||
        }
 | 
			
		||||
        return List.of(lands);
 | 
			
		||||
    }
 | 
			
		||||
//TODO Java Doc more details
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method checks for the player with the longest road according to the siedler game rules.
 | 
			
		||||
     * This method checks for the player with the longest road according to the Siedler game rules.
 | 
			
		||||
     *
 | 
			
		||||
     * @param factionList a List with all factions which can place structures on the board
 | 
			
		||||
     * @return the faction who owns the longest road with minimum length of 5, null there is no road longer then 4
 | 
			
		||||
| 
						 | 
				
			
			@ -161,19 +168,14 @@ public class SiedlerBoard extends HexBoard<Config.Land, Settlement, Road, String
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        for (Config.Faction factionA : players.keySet()) {
 | 
			
		||||
            if (players.get(factionA) > longestRoadLenth && players.get(factionA) > 4) {
 | 
			
		||||
            if (players.get(factionA) > longestRoadLength && players.get(factionA) > 4) {
 | 
			
		||||
                longestRoadFaction = factionA;
 | 
			
		||||
                longestRoadLenth = players.get(factionA);
 | 
			
		||||
                longestRoadLength = players.get(factionA);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return longestRoadFaction;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //todo javadoc
 | 
			
		||||
    public int getLongestRoadLenth() {
 | 
			
		||||
        return longestRoadLenth;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,10 @@ package ch.zhaw.catan;
 | 
			
		|||
import ch.zhaw.catan.Config.Land;
 | 
			
		||||
import ch.zhaw.hexboard.HexBoardTextView;
 | 
			
		||||
 | 
			
		||||
//TODO Java Docs
 | 
			
		||||
/**
 | 
			
		||||
 * This Class extends the Class HexBoardTextView
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
public class SiedlerBoardTextView extends HexBoardTextView<Land, Settlement, Road, String> {
 | 
			
		||||
 | 
			
		||||
  public SiedlerBoardTextView(SiedlerBoard board) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,10 +10,8 @@ import java.util.Random;
 | 
			
		|||
 | 
			
		||||
/**
 | 
			
		||||
 * This class performs all actions related to modifying the game state.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * TODO: (your documentation)
 | 
			
		||||
 *
 | 
			
		||||
 * @author TODO
 | 
			
		||||
 * @author Andrin Fassbind, Leonardo Brandenberger, Roman Schenk, Stefan Amador
 | 
			
		||||
 */
 | 
			
		||||
public class SiedlerGame {
 | 
			
		||||
    static final int FOUR_TO_ONE_TRADE_OFFER = 4;
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +72,14 @@ public class SiedlerGame {
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO JavaDoc
 | 
			
		||||
    /**
 | 
			
		||||
     * This methode is used to add resources to the player.
 | 
			
		||||
     *
 | 
			
		||||
     * @param player the active Player
 | 
			
		||||
     * @param resource the resource to add
 | 
			
		||||
     * @param numberToAdd the quantity of resources to add
 | 
			
		||||
     * @return true if resource has been added else false
 | 
			
		||||
     */
 | 
			
		||||
    private boolean addResourcesToPlayer(Player player, Config.Resource resource, int numberToAdd) {
 | 
			
		||||
        if (bank.getResourceFromBank(resource, numberToAdd)) {
 | 
			
		||||
            player.addResource(resource, numberToAdd);
 | 
			
		||||
| 
						 | 
				
			
			@ -83,7 +88,14 @@ public class SiedlerGame {
 | 
			
		|||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO JavaDoc
 | 
			
		||||
    /**
 | 
			
		||||
     * This methode is used to subtract resources from Player
 | 
			
		||||
     *
 | 
			
		||||
     * @param player the active player
 | 
			
		||||
     * @param resource the resource to subtract
 | 
			
		||||
     * @param numberToSubtract the quantity of resource to subtract
 | 
			
		||||
     * @return true if resource has been subtracted
 | 
			
		||||
     */
 | 
			
		||||
    private boolean subtractResourceFromPlayer(Player player, Config.Resource resource, int numberToSubtract) {
 | 
			
		||||
        if (player.subtractResource(resource, numberToSubtract)) {
 | 
			
		||||
            bank.storeResourceToBank(resource, numberToSubtract);
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +246,11 @@ public class SiedlerGame {
 | 
			
		|||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO JavaDoc
 | 
			
		||||
    /**
 | 
			
		||||
     * This method handles the case if a 7 has been diced.
 | 
			
		||||
     *
 | 
			
		||||
     * @param player the active player who rolls the dice.
 | 
			
		||||
     */
 | 
			
		||||
    public void handleDiceThrow7(Player player) {
 | 
			
		||||
        ArrayList<Config.Resource> resourceArrayList = new ArrayList<>();
 | 
			
		||||
        HashMap<Config.Resource, Integer> resources = player.getResources();
 | 
			
		||||
| 
						 | 
				
			
			@ -376,7 +392,7 @@ public class SiedlerGame {
 | 
			
		|||
        if (!board.hasEdge(roadStart, roadEnd)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        //2. Check if edge is empty //TODO Check if always inverted is allowed
 | 
			
		||||
        //2. Check if edge is empty
 | 
			
		||||
        if (board.getEdge(roadStart, roadEnd) != null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -482,7 +498,11 @@ public class SiedlerGame {
 | 
			
		|||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Todo Java Doc
 | 
			
		||||
    /**
 | 
			
		||||
     * This methode counts the winpoints of the current player.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the winpoints as an integer
 | 
			
		||||
     */
 | 
			
		||||
    public int getCurrentPlayerWinPoints() {
 | 
			
		||||
        int winPoints = 0;
 | 
			
		||||
        List<Settlement> settlements = board.getCorners();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,7 +41,7 @@ public class SiedlerBoardTest {
 | 
			
		|||
            System.out.println(board.getTextView());
 | 
			
		||||
 | 
			
		||||
            assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList));
 | 
			
		||||
            assertEquals(6, board.getLongestRoadLenth());
 | 
			
		||||
            assertEquals(6, board.getLongestRoadLength());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Test
 | 
			
		||||
| 
						 | 
				
			
			@ -50,7 +50,7 @@ public class SiedlerBoardTest {
 | 
			
		|||
            System.out.println(board.getTextView());
 | 
			
		||||
 | 
			
		||||
            assertEquals(Config.Faction.BLUE, board.getLongestRoadFaction(factionList));
 | 
			
		||||
            assertEquals(5, board.getLongestRoadLenth());
 | 
			
		||||
            assertEquals(5, board.getLongestRoadLength());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue