Class Tetris.Shape

java.lang.Object
uno.anahata.asi.swing.games.Tetris.Shape
Enclosing class:
Tetris

static class Tetris.Shape extends Object
Represents the layout and operations of a single Tetris block geometry.
Author:
anahata
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int[][]
    The relative coordinates grid of the four child nodes.
    private static final int[][][]
    Global constant mapping ordinal types to physical coordinate patterns.
    The category of Tetrominoes shape this instance represents.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new blank shape initialized to NoShape.
  • Method Summary

    Modifier and Type
    Method
    Description
    Translates active tetromino types to high-salience design colors.
    Accessor for the underlying tetromino category.
    int
    Calculates the lowest Y coordinate among all active segment blocks.
    Performs a left-hand 90-degree vector rotation on the shape block coordinates.
    void
    Randomly assigns a tetromino shape excluding NoShape.
    void
    Sets the geometric shape and initializes relative coordinate offsets from coordsTable.
    int
    x(int index)
    Retrieves the relative X coordinate offset for the child segment at the specified index.
    int
    y(int index)
    Retrieves the relative Y coordinate offset for the child segment at the specified index.

    Methods inherited from class Object

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

    • pieceShape

      private Tetris.Tetrominoes pieceShape
      The category of Tetrominoes shape this instance represents.
    • coords

      private final int[][] coords
      The relative coordinates grid of the four child nodes.
    • coordsTable

      private static final int[][][] coordsTable
      Global constant mapping ordinal types to physical coordinate patterns.
  • Constructor Details

    • Shape

      public Shape()
      Constructs a new blank shape initialized to NoShape.
  • Method Details

    • setShape

      public void setShape(Tetris.Tetrominoes shape)
      Sets the geometric shape and initializes relative coordinate offsets from coordsTable.
      Parameters:
      shape - The Tetrominoes category of the shape.
    • setRandomShape

      public void setRandomShape()
      Randomly assigns a tetromino shape excluding NoShape.
    • getColor

      public Color getColor()
      Translates active tetromino types to high-salience design colors.
      Returns:
      The design color of this block.
    • x

      public int x(int index)
      Retrieves the relative X coordinate offset for the child segment at the specified index.
      Parameters:
      index - The 0-based index of the child block.
      Returns:
      relative grid X coordinate offset.
    • y

      public int y(int index)
      Retrieves the relative Y coordinate offset for the child segment at the specified index.
      Parameters:
      index - The 0-based index of the child block.
      Returns:
      relative grid Y coordinate offset.
    • getShape

      public Tetris.Tetrominoes getShape()
      Accessor for the underlying tetromino category.
      Returns:
      The active Tetrominoes ordinal value.
    • minY

      public int minY()
      Calculates the lowest Y coordinate among all active segment blocks.
      Returns:
      the minimum Y offset.
    • rotateLeft

      public Tetris.Shape rotateLeft()
      Performs a left-hand 90-degree vector rotation on the shape block coordinates.
      Returns:
      a new rotated Shape instance.