Updated 'PlayerData' class.
Updated the 'PlayerData' class by replacing the magic constants with the 'Resources' class. In Addition, some JavaDoc texts were updated.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package pp.mdga.game;
|
package pp.mdga.game;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
import pp.mdga.Resources;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to represent PlayerData related to the board
|
* 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
|
* @param color the color of the player
|
||||||
*/
|
*/
|
||||||
public PlayerData(Color color) {
|
public PlayerData(Color color) {
|
||||||
homeNodes = new HomeNode[4];
|
homeNodes = new HomeNode[Resources.MAX_PIECES];
|
||||||
pieces = new Piece[4];
|
pieces = new Piece[Resources.MAX_PIECES];
|
||||||
waitingArea = new Piece[4];
|
waitingArea = new Piece[Resources.MAX_PIECES];
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < Resources.MAX_PIECES; i++) {
|
||||||
homeNodes[i] = new HomeNode();
|
homeNodes[i] = new HomeNode();
|
||||||
pieces[i] = new Piece(color, PieceState.WAITING, i);
|
pieces[i] = new Piece(color, PieceState.WAITING, i);
|
||||||
waitingArea[i] = pieces[i];
|
waitingArea[i] = pieces[i];
|
||||||
@@ -47,9 +48,9 @@ public PlayerData(Color color) {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
private PlayerData() {
|
private PlayerData() {
|
||||||
homeNodes = new HomeNode[4];
|
homeNodes = new HomeNode[Resources.MAX_PIECES];
|
||||||
waitingArea = new Piece[4];
|
waitingArea = new Piece[Resources.MAX_PIECES];
|
||||||
pieces = new Piece[4];
|
pieces = new Piece[Resources.MAX_PIECES];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,7 +114,7 @@ public Piece[] getPieces() {
|
|||||||
* @param piece the piece to be added to the waiting area
|
* @param piece the piece to be added to the waiting area
|
||||||
*/
|
*/
|
||||||
public void addWaitingPiece(Piece piece) {
|
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) {
|
if (waitingArea[i] == null) {
|
||||||
waitingArea[i] = piece;
|
waitingArea[i] = piece;
|
||||||
return;
|
return;
|
||||||
@@ -127,7 +128,7 @@ public void addWaitingPiece(Piece piece) {
|
|||||||
* @return the piece that was removed from the waiting area
|
* @return the piece that was removed from the waiting area
|
||||||
*/
|
*/
|
||||||
public Piece removePieceFromWaitingArea() {
|
public Piece removePieceFromWaitingArea() {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < Resources.MAX_PIECES; i++) {
|
||||||
if (waitingArea[i] != null) {
|
if (waitingArea[i] != null) {
|
||||||
Piece piece = waitingArea[i];
|
Piece piece = waitingArea[i];
|
||||||
waitingArea[i] = null;
|
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) {
|
public boolean homeIncludes(Piece piece) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (Node node : this.homeNodes) {
|
||||||
if (homeNodes[i].getOccupant() == piece) {
|
if (node.getOccupant() == piece) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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) {
|
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) {
|
if (homeNodes[i].getOccupant() == piece) {
|
||||||
return i;
|
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() {
|
public boolean hasPieceInWaitingArea() {
|
||||||
for (Piece piece : waitingArea) {
|
for (Piece piece : waitingArea) {
|
||||||
|
|||||||
Reference in New Issue
Block a user