public class Figure
extends java.lang.Object
Each figure instance can have two states, either attached to a square board or not. When attached, all move and rotation operations are checked so that collisions do not occur with other squares on the board. When not attached, any rotation can be made (and will be kept when attached to a new board).
Modifier and Type | Field and Description |
---|---|
static int |
LEFT_ANGLE_FIGURE
A figure constant used to create a figure forming a left angle.
|
static int |
LINE_FIGURE
A figure constant used to create a figure forming a line.
|
static int |
RIGHT_ANGLE_FIGURE
A figure constant used to create a figure forming a right angle.
|
static int |
S_FIGURE
A figure constant used to create a figure forming an "S".
|
static int |
SQUARE_FIGURE
A figure constant used to create a figure forming a square.
|
static int |
TRIANGLE_FIGURE
A figure constant used to create a figure forming a triangle.
|
static int |
Z_FIGURE
A figure constant used to create a figure forming a "Z".
|
Constructor and Description |
---|
Figure(int type)
Creates a new figure of one of the seven predefined types.
|
Modifier and Type | Method and Description |
---|---|
boolean |
attach(SquareBoard board,
boolean center)
Attaches the figure to a specified square board.
|
void |
detach()
Detaches this figure from its square board.
|
int |
getRotation()
Returns the current figure rotation (orientation).
|
boolean |
hasLanded()
Checks if the figure has landed.
|
boolean |
isAllVisible()
Checks if the figure is fully visible on the square board.
|
boolean |
isAttached()
Checks if this figure is attached to a square board.
|
void |
moveAllWayDown()
Moves the figure all the way down.
|
void |
moveDown()
Moves the figure one step down.
|
void |
moveLeft()
Moves the figure one step to the left.
|
void |
moveRight()
Moves the figure one step to the right.
|
void |
rotateClockwise()
Rotates the figure clockwise.
|
void |
rotateCounterClockwise()
Rotates the figure counter-clockwise.
|
void |
rotateRandom()
Rotates the figure randomly.
|
void |
setRotation(int rotation)
Sets the figure rotation (orientation).
|
public static final int SQUARE_FIGURE
public static final int LINE_FIGURE
public static final int S_FIGURE
public static final int Z_FIGURE
public static final int RIGHT_ANGLE_FIGURE
public static final int LEFT_ANGLE_FIGURE
public static final int TRIANGLE_FIGURE
public Figure(int type) throws java.lang.IllegalArgumentException
type
- the figure type (one of the figure constants)java.lang.IllegalArgumentException
- if the figure type specified
is not recognizedSQUARE_FIGURE
,
LINE_FIGURE
,
S_FIGURE
,
Z_FIGURE
,
RIGHT_ANGLE_FIGURE
,
LEFT_ANGLE_FIGURE
,
TRIANGLE_FIGURE
public boolean isAttached()
public boolean attach(SquareBoard board, boolean center)
The horizontal and vertical coordinates will be reset for the figure, when centering the figure on the new board. The figure orientation (rotation) will be kept, however. If the figure was previously attached to another board, it will be detached from that board before attaching to the new board.
board
- the square board to attach tocenter
- the centered position flagpublic void detach()
public boolean isAllVisible()
public boolean hasLanded()
public void moveLeft()
public void moveRight()
public void moveDown()
public void moveAllWayDown()
public int getRotation()
public void setRotation(int rotation)
rotation
- the new figure orientationpublic void rotateRandom()
public void rotateClockwise()
public void rotateCounterClockwise()