package pp.mdga.game; /** * This class is used to represent PlayerData related to the board */ public class PlayerData { private HomeNode[] homeNodes; private int startNodeIndex; private Piece[] waitingArea; private Piece[] pieces; /** * This constructor is used to create a new PlayerData object * * @param color the color of the player */ public PlayerData(Color color) { homeNodes = new HomeNode[4]; waitingArea = new Piece[4]; for (int i = 0; i < 4; i++) { homeNodes[i] = new HomeNode(); pieces[i] = new Piece(color, PieceState.WAITING); waitingArea[i] = pieces[i]; } } /** * This method returns an Array of HomeNodes * * @return the array of HomeNodes */ public Node[] getHomeNodes() { return homeNodes; } /** * This method returns the index of the StartNode * * @return the index of the StartNode */ public int getStartNodeIndex() { return startNodeIndex; } /** * This method sets the index of the startNode. * * @param startNodeIndex the integer index of the startNode */ public void setStartNodeIndex(int startNodeIndex) { this.startNodeIndex = startNodeIndex; } /** * This method returns an array pieces representing the waiting area. * * @return the waiting area */ public Piece[] getWaitingArea() { return waitingArea; } /** * This method returns an array of pieces with all the players pieces * * @return the array of pieces */ public Piece[] getPieces() { return pieces; } /** * This method adds a piece to the waiting area * * @param piece the piece to be added to the waiting area */ public void addWaitingPiece(Piece piece) { for (int i = 0; i < 4; i++) { if (waitingArea[i] == null) { waitingArea[i] = piece; return; } } } /** * This method removes a piece from the waiting area * * @return the piece that was removed from the waiting area */ public Piece removePieceFromWaitingArea() { for (int i = 0; i < 4; i++) { if (waitingArea[i] != null) { Piece piece = waitingArea[i]; waitingArea[i] = null; return piece; } } return null; } /** * This method sets a piece at the given index in the home area * * @param index the index of the node * @param piece the piece to be set at the given index */ public void setPieceInHome(int index, Piece piece) { homeNodes[index].setOccupant(piece); } }