Package pile

Class Pile

java.lang.Object
pile.Pile
Direct Known Subclasses:
Active, Bench, Deck, DiscardPile, Hand, Prize

public abstract class Pile extends Object
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
    Modifier and Type
    Field
    Description
    protected List<Card>
    The list of cards in the pile.
    private int
    The size of the pile (the number of cards in the pile).
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor to initialize a pile, creating an empty list of cards and setting the size to 0.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addCard(Card card)
    Adds a card to the pile and increments the size of the pile.
    void
    Displays the cards in the pile and their indices in a numbered list format.
    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.
    Returns the list of cards in the pile.
    int
    Returns the size of the pile (the number of cards in the pile).
    boolean
    Checks if the pile is empty (i.e., has no cards).
    void
    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
    Shuffles the cards in the pile using the provided Collections.shuffle() method to randomize the order of the cards.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • cards

      protected List<Card> cards
      The list of cards in the pile.
    • size

      private int size
      The 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

      public void addCard(Card card)
      Adds a card to the pile and increments the size of the pile.
      Parameters:
      card - The card to be added to the pile.
    • removeCard

      public void removeCard(Card card)
      Removes a card from the pile and decrements the size of the pile.
      Parameters:
      card - The card to be removed from the pile.
    • drawCard

      public Card 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

      public Card getCardAtIndex(int index)
      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

      public List<Card> 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.