From 29d8e791f6c8bdb9a767ac3fb67c09cc836bf33f Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Wed, 4 Dec 2024 02:44:28 +0100 Subject: [PATCH] Updated 'Player' class. Updated the 'Player' class by adding the 'setPieceInHome' method to it. --- .../src/main/java/pp/mdga/game/Player.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 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 baa88d6f..41cb92f1 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 @@ -48,6 +48,13 @@ public class Player { private Piece[] waitingArea = new Piece[Resources.MAX_PIECES]; private Piece[] pieces = new Piece[Resources.MAX_PIECES]; + /** + * Constructor. + */ + public Player() { + this(""); + } + /** * This constructor constructs a new Player object * @@ -57,13 +64,6 @@ public Player(String name) { this.name = name; } - /** - * Constructor. - */ - public Player() { - this(""); - } - /** * This method will be used to initialize all nodes and pieces of the Player class. */ @@ -81,21 +81,17 @@ public void initialize() { * @param card the card to be added to the players hand */ public void addHandCard(BonusCard card) { - handCards.add(card); + this.handCards.add(card); } /** - * This method returns a BonusCard to be removed from the players hand. + * This method will be used to remove the given card parameter from the handCards attribute of Player card. * - * @param card the cards type to be removed + * @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 BonusCard removeHandCard(BonusCard card) { - BonusCard cardToRemove = handCards.stream().filter(c -> c.equals(card)).findFirst().orElse(null); - if (cardToRemove != null) { - handCards.remove(cardToRemove); - } - return cardToRemove; + public void removeHandCard(BonusCard card) { + this.handCards.remove(card); } /** @@ -248,4 +244,14 @@ public void setReady(boolean ready) { public void setActive(boolean active) { this.active = active; } + + /** + * 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) { + this.homeNodes[index].setOccupant(piece); + } }