From 8a738a3633d8cb71f0ee8b0967373a3af59034ae Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Fri, 6 Dec 2024 00:16:38 +0100 Subject: [PATCH] Updated 'Game' class. Updated the 'Game' class by replacing all 'BonusCard' with 'PowerCard' in it. --- .../src/main/java/pp/mdga/game/Game.java | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java index e66d877c..0ffd7e5b 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Game.java @@ -1,5 +1,10 @@ package pp.mdga.game; +import pp.mdga.game.card.PowerCard; +import pp.mdga.game.card.ShieldCard; +import pp.mdga.game.card.SwapCard; +import pp.mdga.game.card.TurboCard; + import java.util.*; /** @@ -36,12 +41,12 @@ public class Game { /** * The pile of bonus cards available for drawing. */ - private List drawPile = new ArrayList<>(); + private List drawPile = new ArrayList<>(); /** * The pile of bonus cards that have been discarded. */ - private List discardPile = new ArrayList<>(); + private List discardPile = new ArrayList<>(); /** * The game board. @@ -87,18 +92,18 @@ public Game() { * This method initializes the draw pile with the predefined number of bonus cards. */ private void initializeDrawPile() { - addBonusCards(BonusCard.TURBO, AMOUNT_OF_TURBO_CARDS); - addBonusCards(BonusCard.SWAP, AMOUNT_OF_SWAP_CARDS); - addBonusCards(BonusCard.SHIELD, AMOUNT_OF_SHIELD_CARDS); + this.addBonusCards(new TurboCard(), AMOUNT_OF_TURBO_CARDS); + this.addBonusCards(new SwapCard(), AMOUNT_OF_SWAP_CARDS); + this.addBonusCards(new ShieldCard(), AMOUNT_OF_SHIELD_CARDS); Collections.shuffle(this.drawPile); } /** * This method will be used to remove the first card of the drawPile attribute of Game class. * - * @return first card as a BonusCard enumeration. + * @return first card as a PowerCard enumeration. */ - public BonusCard draw() { + public PowerCard draw() { if (!this.drawPile.isEmpty()) { return this.drawPile.remove(0); } @@ -112,7 +117,7 @@ public BonusCard draw() { * @param card the card to add * @param count the number of cards to add */ - private void addBonusCards(BonusCard card, int count) { + private void addBonusCards(PowerCard card, int count) { drawPile.addAll(Collections.nCopies(count, card)); } @@ -314,21 +319,21 @@ public Statistic getGameStatistics() { } /** - * This method returns the draw pile. + * This method will be used to return drawPile attribute of Game class. * - * @return the draw pile + * @return drawPile as a List of PowerCard objects. */ - public List getDrawPile() { - return drawPile; + public List getDrawPile() { + return this.drawPile; } /** - * This method returns the discard pile. + * This method will be used to return discardPile attribute of Game class. * - * @return the discard pile + * @return discardPile as a List of PowerCard objects. */ - public List getDiscardPile() { - return discardPile; + public List getDiscardPile() { + return this.discardPile; } /** @@ -386,20 +391,22 @@ public void setGameStatistics(Statistic gameStatistics) { } /** - * This method sets the draw pile. + * This method will be used to set drawPile attribute of Game class to the given discardPile parameter. + * It will be used to test cases. * - * @param drawPile the new draw pile + * @param drawPile the new value of drawPile attribute as a List of PowerCards. */ - public void setDrawPile(List drawPile) { + public void setDrawPile(List drawPile) { this.drawPile = drawPile; } /** - * This method sets the discard pile. + * This method will be used to set discardPile attribute of Game class to the given discardPile parameter. + * It will be used to test cases. * - * @param discardPile the new discard pile + * @param discardPile the new value of discardPile attribute as a List of PowerCards. */ - public void setDiscardPile(List discardPile) { + public void setDiscardPile(List discardPile) { this.discardPile = discardPile; }