Interface PieceCollection

All Known Implementing Classes:
CompoundPieceCollection, DefaultPieceCollection, LayeredPieceCollection.Collection, SimplePieceCollection

public interface PieceCollection
A PieceCollection generally holds a list of GamePieces on a Map. Each Map has a master CompoundPieceCollection that contains all of its pieces, stacks, and decks -- usually this will be a LayeredPieceCollection but possibly a simpler DefaultPieceCollection. Within a CompoundPieceCollection, there may be several SimplePieceCollections, each containing the pieces in a single visual layer.

In addition to providing a means to maintain a list of all the pieces in a map, this interface provides a means to manage the draw order of pieces, in part by grouping pieces into different visual layers for e.g. Game Piece Layer Control and Game Piece Layer components of a Map. Within each layer, pieces are also listed in the order they should be drawn (i.e. lowest index at the back/bottom, highest index at the front/top).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add​(GamePiece p)
    Adds a piece
    boolean
    Return true if the two pieces can be merged into a single stack
    void
    Remove all pieces
    Return all pieces in the collection, regardless of visibility
    Return all currently-visible pieces in the collection as a read-only array
    int
    Returns the index of a piece.
    void
    Reposition a piece to the back of all others in the same visual layer
    void
    Reposition a piece to the front of all others in the same visual layer
    void
    Removes the piece
  • Method Details

    • moveToFront

      void moveToFront(GamePiece p)
      Reposition a piece to the front of all others in the same visual layer
    • moveToBack

      void moveToBack(GamePiece p)
      Reposition a piece to the back of all others in the same visual layer
    • getPieces

      GamePiece[] getPieces()
      Return all currently-visible pieces in the collection as a read-only array
    • getAllPieces

      GamePiece[] getAllPieces()
      Return all pieces in the collection, regardless of visibility
    • canMerge

      boolean canMerge(GamePiece p1, GamePiece p2)
      Return true if the two pieces can be merged into a single stack
    • indexOf

      int indexOf(GamePiece p)
      Returns the index of a piece. When painting the map, pieces are drawn in order of index -- lowest index drawn first and therefore appearing "below" later pieces which are drawn on top of it.
    • remove

      void remove(GamePiece p)
      Removes the piece
    • add

      void add(GamePiece p)
      Adds a piece
    • clear

      void clear()
      Remove all pieces