Package tetris.model

Class Field

java.lang.Object
tetris.model.Field

public class Field extends Object
The class Field implements the playing field of a Tetris game.
Version:
2.1
Author:
Stephan Fischli
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Set<Block>
    The blocks of the field.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addBlocks(Block[] blocks)
    Adds blocks to the field.
    boolean
    Detects if the specified blocks collide with the border or the blocks of the field.
    Gets the blocks of the field.
    private boolean
    isRowFull(int y)
    Checks if a row is full of blocks.
    int
    Removes the full rows from the field.
    private void
    removeRow(int y)
    Removes the blocks of a row and shifts the blocks of the upper rows down.

    Methods inherited from class java.lang.Object

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

    • blocks

      private final Set<Block> blocks
      The blocks of the field.
  • Constructor Details

    • Field

      public Field()
  • Method Details

    • getBlocks

      public Set<Block> getBlocks()
      Gets the blocks of the field.
      Returns:
      the blocks of the field
    • addBlocks

      public void addBlocks(Block[] blocks)
      Adds blocks to the field.
      Parameters:
      blocks - the blocks to add
    • detectCollision

      public boolean detectCollision(Block[] blocks)
      Detects if the specified blocks collide with the border or the blocks of the field.
      Parameters:
      blocks - the blocks to check for collision
      Returns:
      true if one of the blocks collides, false otherwise
    • removeFullRows

      public int removeFullRows()
      Removes the full rows from the field.
      Returns:
      the number of removed rows
    • isRowFull

      private boolean isRowFull(int y)
      Checks if a row is full of blocks.
      Parameters:
      y - the y-coordinate of the row
      Returns:
      true if the row is full, false otherwise
    • removeRow

      private void removeRow(int y)
      Removes the blocks of a row and shifts the blocks of the upper rows down.
      Parameters:
      y - the y-coordinate of the row