Package sac.model
Class Piece
java.lang.Object
sac.model.Piece
An immutable representation of a Tetris Tetromino.
Each piece is defined by the points that make up its body.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionSorted representation of the points that make up the piece.final int
The height of the Piece.The lowest y value for each column.final Piece.PieceType
The shape of the Piece.final int
The width of the Piece. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if two Pieces have the same body.static Piece
generate
(Piece.PieceType type) Generate a new Piece with specific type.Rotate the Piece counterclockwise by 90 degrees.Rotate the Piece clockwise by 90 degrees.toString()
Get the string representation of the Piece.
-
Field Details
-
type
The shape of the Piece. -
width
public final int widthThe width of the Piece. -
height
public final int heightThe height of the Piece. -
body
Sorted representation of the points that make up the piece. -
lowestYVals
The lowest y value for each column.
-
-
Method Details
-
generate
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
Rotate the Piece counterclockwise by 90 degrees.- Returns:
- The Piece rotated 90 degrees counterclockwise.
-
rotateRight
Rotate the Piece clockwise by 90 degrees.- Returns:
- The Piece rotated 90 degrees clockwise.
-
toString
Get the string representation of the Piece. -
equals
Checks if two Pieces have the same body.
-