java.lang.Object
be.belegkarnil.game.board.spectrangle.Bag
All Implemented Interfaces:
Cloneable

public class Bag extends Object implements Cloneable
The class represents the bag of Piece linked to a Board during a Game.
Author:
Belegkarnil
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Bag()
    Construct a bag with random undefined seed
    protected
    Bag(Bag bag)
    Constructor that clones the bag (see clone())
     
    Bag(Random random)
    Construct a bag with custom Random generator
  • Method Summary

    Modifier and Type
    Method
    Description
    Clone the current bag (note that the random number is different)
    boolean
    Know if the bag is empty
    protected void
    Reset the bag for another round/game.
    int
    Get the number of Pieces the bag has.
    protected Piece
    swap(Piece piece)
    Swap a given Piece by another from the bag
    protected Piece
    Take one Piece from the bag
    protected Piece[]
    take(int amount)
    Take an amount of Piece from the bag (see take()

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Bag

      public Bag()
      Construct a bag with random undefined seed
    • Bag

      protected Bag(Bag bag)
      Constructor that clones the bag (see clone())
      Parameters:
      bag - The bag to clone
    • Bag

      public Bag(Random random)
      Construct a bag with custom Random generator
  • Method Details

    • swap

      protected Piece swap(Piece piece)
      Swap a given Piece by another from the bag
      Parameters:
      piece - The Piece to swap
      Returns:
      A new Piece taken from the bag
    • take

      protected Piece[] take(int amount)
      Take an amount of Piece from the bag (see take()
      Parameters:
      amount - The amount of Piece to take
      Returns:
      An array of Pieces taken from the bag
    • reset

      protected void reset()
      Reset the bag for another round/game. All Piece are put into the bag.
    • take

      protected Piece take()
      Take one Piece from the bag
      Returns:
      A Piece extracted from the bag
    • size

      public int size()
      Get the number of Pieces the bag has.
      Returns:
      The number of Pieces that are in the bag
    • isEmpty

      public boolean isEmpty()
      Know if the bag is empty
      Returns:
      true iff the bag contains no Piece
    • clone

      public Object clone() throws CloneNotSupportedException
      Clone the current bag (note that the random number is different)
      Overrides:
      clone in class Object
      Returns:
      a clone of the bag state
      Throws:
      CloneNotSupportedException