Package pile
Class Pile
java.lang.Object
pile.Pile
This class represents a generic pile of cards in the Pokémon Trading Card Game.
It provides methods to add, remove, draw, shuffle, get card(s), get size, check if empty, and display the cards in the pile.
It is an abstract class that serves as a base for specific pile types such as Deck, Hand, Active, Bench, Prize, and DiscardPile.
- Version:
- 1.0
- Author:
- Tyler Mong
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPile()
Constructor to initialize a pile, creating an empty list of cards and setting the size to 0. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a card to the pile and increments the size of the pile.void
display()
Displays the cards in the pile and their indices in a numbered list format.drawCard()
Draws a card from the top of the pile and decrements the size of the pile it is drawn from.getCardAtIndex
(int index) Returns the card at the specified index in the pile.getCards()
Returns the list of cards in the pile.int
getSize()
Returns the size of the pile (the number of cards in the pile).boolean
isEmpty()
Checks if the pile is empty (i.e., has no cards).void
removeCard
(Card card) Removes a card from the pile and decrements the size of the pile.void
Displays the cards in the pile and their indices in a numbered list format, starting from index 2.void
shuffle()
Shuffles the cards in the pile using the provided Collections.shuffle() method to randomize the order of the cards.
-
Field Details
-
cards
The list of cards in the pile. -
size
private int sizeThe size of the pile (the number of cards in the pile).
-
-
Constructor Details
-
Pile
public Pile()Constructor to initialize a pile, creating an empty list of cards and setting the size to 0. This constructor is called by the subclasses to create a new pile of cards.
-
-
Method Details
-
addCard
Adds a card to the pile and increments the size of the pile.- Parameters:
card
- The card to be added to the pile.
-
removeCard
Removes a card from the pile and decrements the size of the pile.- Parameters:
card
- The card to be removed from the pile.
-
drawCard
Draws a card from the top of the pile and decrements the size of the pile it is drawn from.- Returns:
- The card drawn from the top of the pile, or null if the pile is empty.
-
shuffle
public void shuffle()Shuffles the cards in the pile using the provided Collections.shuffle() method to randomize the order of the cards. -
getCardAtIndex
Returns the card at the specified index in the pile.- Parameters:
index
- The index of the card to be retrieved from the pile.- Returns:
- The card at the specified index in the pile.
-
getCards
Returns the list of cards in the pile.- Returns:
- The list of cards in the pile.
-
getSize
public int getSize()Returns the size of the pile (the number of cards in the pile).- Returns:
- The size of the pile.
-
isEmpty
public boolean isEmpty()Checks if the pile is empty (i.e., has no cards).- Returns:
- True if the pile is empty, false otherwise.
-
display
public void display()Displays the cards in the pile and their indices in a numbered list format. -
secondaryDisplay
public void secondaryDisplay()Displays the cards in the pile and their indices in a numbered list format, starting from index 2. This method is used specifically in the Game.attachEnergy(Player) method to display benched Pokémon cards, accounting for the active Pokémon at index 1.
-