From 2a84e7cf65dff3998ef519ee94d38be71d7e9811 Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Tue, 3 Dec 2024 00:51:45 +0100 Subject: [PATCH] Updated 'Player' class. Updated the 'Player' class by moving all content of 'PlayerData' class in 'Player' class. --- .../src/main/java/pp/mdga/game/Player.java | 175 +++++++++++++----- 1 file changed, 127 insertions(+), 48 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java index 0dd875f0..baa88d6f 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Player.java @@ -1,6 +1,7 @@ package pp.mdga.game; import com.jme3.network.serializing.Serializable; +import pp.mdga.Resources; import java.util.ArrayList; @@ -17,12 +18,12 @@ public class Player { /** * The statistics of the player. */ - private Statistic playerStatistic; + private Statistic playerStatistic = new Statistic(); /** * The hand cards of the player. */ - private ArrayList handCards; + private ArrayList handCards = new ArrayList<>(); /** * The color of the player. @@ -32,13 +33,21 @@ public class Player { /** * Indicates if the player is ready. */ - private boolean isReady; + private boolean ready = false; /** * Indicates if the player is active. */ 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 * @@ -46,8 +55,6 @@ public class Player { */ public Player(String 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 - * - * @return the name of the player as a String + * This method will be used to initialize all nodes and pieces of the Player class. */ - public String getName() { - return name; - } - - /** - * 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 getHandCards() { - return handCards; + public void initialize() { + 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]; + } } /** @@ -116,6 +98,58 @@ public BonusCard removeHandCard(BonusCard card) { 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 getHandCards() { + return handCards; + } + /** * This method returns the color of the player * @@ -125,22 +159,13 @@ public Color getColor() { 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 * * @return true if the player is ready, false otherwise */ public boolean isReady() { - return isReady; + return ready; } /** @@ -152,13 +177,67 @@ public boolean isActive() { 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 * * @param ready true if the player is ready, false otherwise */ public void setReady(boolean ready) { - isReady = ready; + this.ready = ready; } /**