Package sac.model

Class Piece

java.lang.Object
sac.model.Piece

public class Piece extends Object
An immutable representation of a Tetris Tetromino. Each piece is defined by the points that make up its body.
  • Field Details

    • type

      public final Piece.PieceType type
      The shape of the Piece.
    • width

      public final int width
      The width of the Piece.
    • height

      public final int height
      The height of the Piece.
    • body

      public final ArrayList<Point> body
      Sorted representation of the points that make up the piece.
    • lowestYVals

      public final ArrayList<Integer> lowestYVals
      The lowest y value for each column.
  • Method Details

    • generate

      public static Piece generate(Piece.PieceType type)
      Generate a new Piece with specific type.
      Parameters:
      type - The type of the Piece.
      Returns:
      A Piece with specific type, initialized with fast rotations.
    • rotateLeft

      public Piece rotateLeft()
      Rotate the Piece counterclockwise by 90 degrees.
      Returns:
      The Piece rotated 90 degrees counterclockwise.
    • rotateRight

      public Piece rotateRight()
      Rotate the Piece clockwise by 90 degrees.
      Returns:
      The Piece rotated 90 degrees clockwise.
    • toString

      public String toString()
      Get the string representation of the Piece.
      Overrides:
      toString in class Object
      Returns:
      The string representation of the Piece.
    • equals

      public boolean equals(Object obj)
      Checks if two Pieces have the same body.
      Overrides:
      equals in class Object
      Parameters:
      obj - The other object.
      Returns:
      If the other object is a Piece and they have the same body.