|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectPiece
public class Piece
Piece represents a rectangular piece in the puzzle. Pieces can move horizontally, vertically, or both, but movement occurrs in only one direction at a time. Piece position and dimensions are immutable. Movement is acheived by generating a list of new pieces in the various possible positions resulting from the "movement" of this piece.
| Field Summary | |
|---|---|
static char |
H_MOVE
|
private int |
height
|
private char |
movement
|
private java.lang.String |
name
|
static char |
V_MOVE
|
private int |
width
|
private int |
x
|
private int |
y
|
| Constructor Summary | |
|---|---|
Piece(int x,
int y,
int width,
int height,
char movement)
Constructor: initializes a piece that is not yet part of any puzzle |
|
Piece(int x,
int y,
int width,
int height,
char movement,
java.lang.String name)
Private Constructor: used for cloning, does no error checking |
|
| Method Summary | |
|---|---|
void |
addedToPuzzle(Puzzle puzzle)
Informs the piece that it has been added to the specified puzzle. |
private boolean |
addMove(Puzzle puzzle,
java.util.Collection moves,
char axis,
int delta)
Checks if the piece fits after moving delta spaces along the specified axis. |
void |
checkFit(Puzzle puzzle)
Checks if the piece can fit into the puzzle without overlapping any other piece or hanging off the edge of the board. |
int |
getHeight()
Accessor for height |
char |
getMovement()
Accessor for axes of movement |
java.lang.String |
getName()
Accessor for name |
java.util.Collection |
getValidMoves(Puzzle puzzle)
Finds a list of all valid moves that the piece can make. |
int |
getWidth()
Accessor for width |
int |
getX()
Accessor for x |
int |
getY()
Accessor for y |
void |
setName(java.lang.String newName)
Mutator for name |
java.lang.String |
toString()
Generates a string representation of the piece |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private java.lang.String name
private int x
private int y
private int width
private int height
private char movement
public static final char H_MOVE
public static final char V_MOVE
| Constructor Detail |
|---|
public Piece(int x,
int y,
int width,
int height,
char movement)
throws PuzzleException
x - the column where the piece livesy - the row where the piece liveswidth - the width of the piece (in columns)height - the height of the piece (in rows)movement - bit mask of piece's movement ability: V_MOVE, H_MOVE
PuzzleException - if any of the parameters are invalid
public Piece(int x,
int y,
int width,
int height,
char movement,
java.lang.String name)
x - the column where the piece livesy - the row where the piece liveswidth - the width of the piece (in columns)height - the height of the piece (in rows)movement - bit mask of piece's movement ability: V_MOVE, H_MOVE| Method Detail |
|---|
public void checkFit(Puzzle puzzle)
throws PuzzleException
puzzle - the puzzle to check if the piece will fit
PuzzleException - if the piece cannot fit into the puzzlepublic void addedToPuzzle(Puzzle puzzle)
puzzle - the puzzle to which the piece has been addedpublic java.lang.String toString()
toString in class java.lang.Objectpublic void setName(java.lang.String newName)
newName - the new name of the piecepublic java.lang.String getName()
public int getX()
public int getY()
public int getWidth()
public int getHeight()
public char getMovement()
public java.util.Collection getValidMoves(Puzzle puzzle)
puzzle - the puzzle where the piece lives
private boolean addMove(Puzzle puzzle,
java.util.Collection moves,
char axis,
int delta)
puzzle - the puzzle where the piece livesmoves - the list of moves (new move gets added to this)axis - the axis of movement: H_MOVE or V_MOVEdelta - the distance and direction of travel along the axis
java.lang.IllegalArgumentException - if moves is null, delta is zero, or axis
is not equal to H_MOVE and not equal to V_MOVE
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||