Updated the 'Player' class.

Updated the 'Player' class by adjusting the JavaDocs and writing the logic for the 'isFinished()' method.
This commit is contained in:
Daniel Grigencha
2024-12-05 04:54:12 +01:00
parent 154efccf31
commit 6576250113

View File

@@ -6,7 +6,7 @@
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* This class will be used to handle general PlayerData * This class represents a player in the game.
*/ */
@Serializable @Serializable
public class Player { public class Player {
@@ -44,8 +44,20 @@ public class Player {
* Node and piece attributes * Node and piece attributes
*/ */
private int startNodeIndex = -1; private int startNodeIndex = -1;
/**
* The home nodes of the player.
*/
private HomeNode[] homeNodes = new HomeNode[Resources.MAX_PIECES]; private HomeNode[] homeNodes = new HomeNode[Resources.MAX_PIECES];
/**
* The waiting area of the player.
*/
private Piece[] waitingArea = new Piece[Resources.MAX_PIECES]; private Piece[] waitingArea = new Piece[Resources.MAX_PIECES];
/**
* The pieces of the player.
*/
private Piece[] pieces = new Piece[Resources.MAX_PIECES]; private Piece[] pieces = new Piece[Resources.MAX_PIECES];
/** /**
@@ -88,7 +100,6 @@ public void addHandCard(BonusCard card) {
* This method will be used to remove the given card parameter from the handCards attribute of Player card. * This method will be used to remove the given card parameter from the handCards attribute of Player card.
* *
* @param card as the card which should be removed from the handCards attribute as a PowerCard object. * @param card as the card which should be removed from the handCards attribute as a PowerCard object.
* @return the removed card or null if there is none of that card type
*/ */
public void removeHandCard(BonusCard card) { public void removeHandCard(BonusCard card) {
this.handCards.remove(card); this.handCards.remove(card);
@@ -116,8 +127,13 @@ public void addWaitingPiece(Piece piece) {
* @return true or false. * @return true or false.
*/ */
public boolean isFinished() { public boolean isFinished() {
for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (this.pieces[i].getState() != PieceState.HOMEFINISHED) {
return false; return false;
} }
}
return true;
}
/** /**
* This method returns the give name of the Player * This method returns the give name of the Player
@@ -255,6 +271,11 @@ public void setPieceInHome(int index, Piece piece) {
this.homeNodes[index].setOccupant(piece); this.homeNodes[index].setOccupant(piece);
} }
/**
* The string representation of the player
*
* @return the string representation of the player
*/
@Override @Override
public String toString() { public String toString() {
return "Player: " + name + " Color: " + color; return "Player: " + name + " Color: " + color;