Package tetris.model
Class Field
java.lang.Object
tetris.model.Field
The class Field implements the playing field of a Tetris game.
- Version:
- 2.1
- Author:
- Stephan Fischli
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds blocks to the field.boolean
detectCollision
(Block[] blocks) 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.
-
Field Details
-
blocks
The blocks of the field.
-
-
Constructor Details
-
Field
public Field()
-
-
Method Details
-
getBlocks
Gets the blocks of the field.- Returns:
- the blocks of the field
-
addBlocks
Adds blocks to the field.- Parameters:
blocks
- the blocks to add
-
detectCollision
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
-