diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java index cb2a788b..ae3387e4 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/PlayerData.java @@ -1,6 +1,7 @@ package pp.mdga.game; import com.jme3.network.serializing.Serializable; +import pp.mdga.Resources; /** * This class is used to represent PlayerData related to the board @@ -33,10 +34,10 @@ public class PlayerData { * @param color the color of the player */ public PlayerData(Color color) { - homeNodes = new HomeNode[4]; - pieces = new Piece[4]; - waitingArea = new Piece[4]; - for (int i = 0; i < 4; i++) { + homeNodes = new HomeNode[Resources.MAX_PIECES]; + pieces = new Piece[Resources.MAX_PIECES]; + waitingArea = new Piece[Resources.MAX_PIECES]; + for (int i = 0; i < Resources.MAX_PIECES; i++) { homeNodes[i] = new HomeNode(); pieces[i] = new Piece(color, PieceState.WAITING, i); waitingArea[i] = pieces[i]; @@ -47,9 +48,9 @@ public PlayerData(Color color) { * Constructor. */ private PlayerData() { - homeNodes = new HomeNode[4]; - waitingArea = new Piece[4]; - pieces = new Piece[4]; + homeNodes = new HomeNode[Resources.MAX_PIECES]; + waitingArea = new Piece[Resources.MAX_PIECES]; + pieces = new Piece[Resources.MAX_PIECES]; } /** @@ -113,7 +114,7 @@ public Piece[] getPieces() { * @param piece the piece to be added to the waiting area */ public void addWaitingPiece(Piece piece) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < Resources.MAX_PIECES; i++) { if (waitingArea[i] == null) { waitingArea[i] = piece; return; @@ -127,7 +128,7 @@ public void addWaitingPiece(Piece piece) { * @return the piece that was removed from the waiting area */ public Piece removePieceFromWaitingArea() { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < Resources.MAX_PIECES; i++) { if (waitingArea[i] != null) { Piece piece = waitingArea[i]; waitingArea[i] = null; @@ -148,26 +149,30 @@ public void setPieceInHome(int index, Piece piece) { } /** - * This method returns the homeNodes + * This method will be used to return if the given piece parameter is inside the homNodes attribute of PlayerData + * class. + * If yes it will return true, otherwise false. * - * @return the homeNodes + * @return true or false. */ public boolean homeIncludes(Piece piece) { - for (int i = 0; i < 4; i++) { - if (homeNodes[i].getOccupant() == piece) { + for (Node node : this.homeNodes) { + if (node.getOccupant() == piece) { return true; } } + return false; } /** - * This method returns the homeNodes + * This method will be used to return the index of the given piece parameter in the homeNodes attribute of + * PlayerData class. * - * @return the homeNodes + * @return index as an Integer. */ public int getIndexInHome(Piece piece) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < Resources.MAX_PIECES; i++) { if (homeNodes[i].getOccupant() == piece) { return i; } @@ -176,9 +181,10 @@ public int getIndexInHome(Piece piece) { } /** - * This method returns the homeNodes + * This method will be usd to check if the waitingArea attribute of PlayerData class is empty. + * If yes it will return false, otherwise true. * - * @return the homeNodes + * @return true or false. */ public boolean hasPieceInWaitingArea() { for (Piece piece : waitingArea) {