Updated 'Player' class.

Updated the 'Player' class by moving all content of 'PlayerData' class in 'Player' class.
This commit is contained in:
Daniel Grigencha
2024-12-03 00:51:45 +01:00
parent 3a02edb944
commit 2a84e7cf65

View File

@@ -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;
import java.util.ArrayList; import java.util.ArrayList;
@@ -17,12 +18,12 @@ public class Player {
/** /**
* The statistics of the player. * The statistics of the player.
*/ */
private Statistic playerStatistic; private Statistic playerStatistic = new Statistic();
/** /**
* The hand cards of the player. * The hand cards of the player.
*/ */
private ArrayList<BonusCard> handCards; private ArrayList<BonusCard> handCards = new ArrayList<>();
/** /**
* The color of the player. * The color of the player.
@@ -32,13 +33,21 @@ public class Player {
/** /**
* Indicates if the player is ready. * Indicates if the player is ready.
*/ */
private boolean isReady; private boolean ready = false;
/** /**
* Indicates if the player is active. * Indicates if the player is active.
*/ */
private boolean active = true; private boolean active = true;
/**
* Node and piece attributes
*/
private int startNodeIndex = -1;
private HomeNode[] homeNodes = new HomeNode[Resources.MAX_PIECES];
private Piece[] waitingArea = new Piece[Resources.MAX_PIECES];
private Piece[] pieces = new Piece[Resources.MAX_PIECES];
/** /**
* This constructor constructs a new Player object * This constructor constructs a new Player object
* *
@@ -46,8 +55,6 @@ public class Player {
*/ */
public Player(String name) { public Player(String name) {
this.name = name; this.name = name;
playerStatistic = new Statistic();
handCards = new ArrayList<>();
} }
/** /**
@@ -58,39 +65,14 @@ public Player() {
} }
/** /**
* This method returns the give name of the Player * This method will be used to initialize all nodes and pieces of the Player class.
*
* @return the name of the player as a String
*/ */
public String getName() { public void initialize() {
return name; for (int index = 0; index < Resources.MAX_PIECES; index++) {
this.homeNodes[index] = new HomeNode();
this.pieces[index] = new Piece(this.color, PieceState.WAITING);
this.waitingArea[index] = this.pieces[index];
} }
/**
* This method sets the name of the player
*
* @param name the new name of the player
*/
public void setName(String name) {
this.name = name;
}
/**
* This methode returns the statistics of the player
*
* @return the statistics of the player
*/
public Statistic getPlayerStatistic() {
return playerStatistic;
}
/**
* This method returns the current handCards of the player
*
* @return the handCards of the player
*/
public ArrayList<BonusCard> getHandCards() {
return handCards;
} }
/** /**
@@ -116,6 +98,58 @@ public BonusCard removeHandCard(BonusCard card) {
return cardToRemove; return cardToRemove;
} }
/**
* This method will be used to add the given piece parameter to the first free slot inside the waitingArea attribute
* of Player class.
*
* @param piece as the piece which should be added to the waitingArea attribute of Player class as a Piece object.
*/
public void addWaitingPiece(Piece piece) {
for (int i = 0; i < Resources.MAX_PIECES; i++) {
if (this.waitingArea[i] == null) {
this.waitingArea[i] = piece;
return;
}
}
}
/**
* This method will be used to check if the player is finished.
* ToDo: Currently return always false. Implement logic!
*
* @return true or false.
*/
public boolean isFinished() {
return false;
}
/**
* This method returns the give name of the Player
*
* @return the name of the player as a String
*/
public String getName() {
return name;
}
/**
* This methode returns the statistics of the player
*
* @return the statistics of the player
*/
public Statistic getPlayerStatistic() {
return playerStatistic;
}
/**
* This method returns the current handCards of the player
*
* @return the handCards of the player
*/
public ArrayList<BonusCard> getHandCards() {
return handCards;
}
/** /**
* This method returns the color of the player * This method returns the color of the player
* *
@@ -125,22 +159,13 @@ public Color getColor() {
return color; return color;
} }
/**
* This method sets the color of the player
*
* @param color the new color of the player
*/
public void setColor(Color color) {
this.color = color;
}
/** /**
* This method returns if the player is ready * This method returns if the player is ready
* *
* @return true if the player is ready, false otherwise * @return true if the player is ready, false otherwise
*/ */
public boolean isReady() { public boolean isReady() {
return isReady; return ready;
} }
/** /**
@@ -152,13 +177,67 @@ public boolean isActive() {
return this.active; return this.active;
} }
/**
* This method will be used to return startNodeIndex of Player class.
*
* @return startNodeIndex as an Integer.
*/
public int getStartNodeIndex() {
return this.startNodeIndex;
}
/**
* This method will be used to return homeNodes attribute of Player class.
*
* @return homeNodes as an Array of Node objects.
*/
public Node[] getHomeNodes() {
return this.homeNodes;
}
/**
* This method will be used to return waitingArea attribute of Player class.
*
* @return waitingArea as an Array of Piece objects.
*/
public Piece[] getWaitingArea() {
return this.waitingArea;
}
/**
* This method will be used to return pieces attribute of Player class.
*
* @return pieces as an Array of Piece objects.
*/
public Piece[] getPieces() {
return this.pieces;
}
/**
* This method sets the name of the player
*
* @param name the new name of the player
*/
public void setName(String name) {
this.name = name;
}
/**
* This method sets the color of the player
*
* @param color the new color of the player
*/
public void setColor(Color color) {
this.color = color;
}
/** /**
* This method sets the player to ready * This method sets the player to ready
* *
* @param ready true if the player is ready, false otherwise * @param ready true if the player is ready, false otherwise
*/ */
public void setReady(boolean ready) { public void setReady(boolean ready) {
isReady = ready; this.ready = ready;
} }
/** /**