Updated 'Game' class.

Updated the 'Game' class by replacing all 'BonusCard' with 'PowerCard' in it.
This commit is contained in:
Daniel Grigencha
2024-12-06 00:16:38 +01:00
parent 3a32a7ebf7
commit 8a738a3633

View File

@@ -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<BonusCard> drawPile = new ArrayList<>();
private List<PowerCard> drawPile = new ArrayList<>();
/**
* The pile of bonus cards that have been discarded.
*/
private List<BonusCard> discardPile = new ArrayList<>();
private List<PowerCard> 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<BonusCard> getDrawPile() {
return drawPile;
public List<PowerCard> 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<BonusCard> getDiscardPile() {
return discardPile;
public List<PowerCard> 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<BonusCard> drawPile) {
public void setDrawPile(List<PowerCard> 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<BonusCard> discardPile) {
public void setDiscardPile(List<PowerCard> discardPile) {
this.discardPile = discardPile;
}