Updated 'Board' class.

Updated the 'Board' class by removing the 'playerData' attribute and its getter method from it.
This commit is contained in:
Daniel Grigencha
2024-12-04 02:42:16 +01:00
parent c0b72ae4da
commit b8ed5060d6

View File

@@ -2,15 +2,14 @@
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import java.util.HashMap;
import java.util.Map;
/** /**
* This class will be used to hold all Board relevant data. * This class will be used to hold all Board relevant data.
*/ */
@Serializable @Serializable
public class Board { public class Board {
private Map<Color, PlayerData> playerData = new HashMap<>(); /**
* Create Board attributes.
*/
private final Node[] infield; private final Node[] infield;
/** /**
@@ -35,23 +34,18 @@ public Board() {
} }
/** /**
* This method will be used to add the given color and playerData parameters to the playerData attribute of * This method returns the index of a specific piece on the board
* Board class.
* *
* @param color as the color of the player as a Color enumeration. * @param piece the piece to be searched for
* @param playerData as the playerData of the player as a PlayerData object. * @return the index of the piece
*/ */
public void addPlayerData(Color color, PlayerData playerData) { public int getInfieldIndexOfPiece(Piece piece) {
this.playerData.put(color, playerData); for (int i = 0; i < infield.length; i++) {
} if (infield[i].getOccupant() == piece) {
return i;
/** }
* This method returns the playerData }
* return -1;
* @return the playerData
*/
public Map<Color, PlayerData> getPlayerData() {
return playerData;
} }
/** /**
@@ -72,19 +66,4 @@ public Node[] getInfield() {
public void setPieceOnBoard(int index, Piece piece) { public void setPieceOnBoard(int index, Piece piece) {
infield[index].setOccupant(piece); infield[index].setOccupant(piece);
} }
/**
* This method returns the index of a specific piece on the board
*
* @param piece the piece to be searched for
* @return the index of the piece
*/
public int getInfieldIndexOfPiece(Piece piece) {
for (int i = 0; i < infield.length; i++) {
if (infield[i].getOccupant() == piece) {
return i;
}
}
return -1;
}
} }