Files
Gruppe-01-fin/Projekte/mdga/model/src/main/java/pp.mdga/game/PlayerData.java
Fleischer Hanno 806f0d7d9d added message contents to the messages
addedn the conentents for all messages regarding the BPMN diagramm and own interpretation.
also created an identifier for pieces to be used for network communication between server and client so that they talk about the same piece.
2024-11-23 12:26:20 +01:00

154 lines
3.6 KiB
Java

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, i);
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);
}
/**
* This method returns the homeNodes
*
* @return the homeNodes
*/
public boolean homeIncludes(Piece piece) {
for (int i = 0; i < 4; i++) {
if (homeNodes[i].getOccupant() == piece) {
return true;
}
}
return false;
}
/**
* This method returns the homeNodes
*
* @return the homeNodes
*/
public int getIndexInHome(Piece piece) {
for (int i = 0; i < 4; i++) {
if (homeNodes[i].getOccupant() == piece) {
return i;
}
}
return -1;
}
/**
* This method returns the homeNodes
*
* @return the homeNodes
*/
public boolean hasPieceInWaitingArea() {
for (Piece piece : waitingArea) {
if (piece != null) {
return true;
}
}
return false;
}
}