|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.util.Observable
Piece
public abstract class Piece
An abstract class that represents a playing piece. This class, together with Board, can be used to display board games. This class is only for display purposes; logic for the game should be in user-defined classes.
| Constructor Summary | |
|---|---|
Piece()
Creates a Piece. |
|
| Method Summary | |
|---|---|
boolean |
canMove(int deltaRow,
int deltaColumn)
Determines whether this piece can be moved to the new location. |
boolean |
canMoveTo(int newRow,
int newColumn)
Determines whether this piece can be moved to the specified location. |
void |
dump()
Debugging method to print out the status of this Piece. |
Board |
getBoard()
|
int |
getColumn()
Returns the column that this piece is in, or -1 if this piece is not on the board. |
int |
getRow()
Returns the row that this piece is in, or -1 if this piece is not on the board. |
int |
getSpeed()
Get the speed (in pixels/redraw) at which this piece will move. |
boolean |
isDraggable()
Returns true if the piece can be dragged by the mouse. |
boolean |
isSelectable()
Returns true if the piece can be selected by the mouse. |
boolean |
move(int deltaRow,
int deltaColumn)
Moves this piece the given number of rows and columns. |
boolean |
moveTo(int newRow,
int newColumn)
Moves this piece to a new position on the board. |
void |
moveToTop()
Ensures that this piece will be drawn on top of any other pieces in the same array location. |
abstract void |
paint(java.awt.Graphics g,
java.awt.Rectangle r)
Paints this piece on the board within the given rectangle; must be implemented by a subclass. |
void |
place(Board board,
int row,
int column)
Places this piece at the given row and column on the board. |
void |
redraw()
Causes this piece to be redrawn. |
void |
redraw(java.awt.Rectangle rect)
Causes the given rectangle to be redrawn. |
void |
remove()
Removes this piece from whatever board it may be on, but does not delete the piece itself. |
void |
setDraggable(boolean draggable)
Determines whether the piece can be dragged by the mouse. |
void |
setSelectable(boolean selectable)
Determines whether the piece can be selected by the mouse. |
void |
setSpeed(int speed)
Sets the speed of movement (in squares/second) for this piece. |
java.lang.String |
toString()
Returns a printable String representing this Piece. |
| Methods inherited from class java.util.Observable |
|---|
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Piece()
board.place(piece, row, column) and
piece.place(board, row, column).
| Method Detail |
|---|
public Board getBoard()
public java.lang.String toString()
toString in class java.lang.Objectpublic void setDraggable(boolean draggable)
draggable - Tell whether the piece can be dragged by user mouse
movement.public boolean isDraggable()
true if the piece can be dragged by the mouse.
true if the piece is draggable.public void setSelectable(boolean selectable)
selectable - Set to true if and only if the piece can be selected by clicking
on it.public boolean isSelectable()
true if the piece can be selected by the mouse.
true if the piece is selectable.public int getRow()
public int getColumn()
public void place(Board board,
int row,
int column)
board - The Board on which to place this piece.row - The row in which to place this piece.column - The column in which to place this piece.public void remove()
public void setSpeed(int speed)
speed - The desired speed of movement, in pixels/redraw.public int getSpeed()
public abstract void paint(java.awt.Graphics g,
java.awt.Rectangle r)
g - The Graphics object on which painting should be done.r - The rectangle in which to paint this piece.public void moveToTop()
public boolean move(int deltaRow,
int deltaColumn)
deltaRow - The number of rows down to move this piece; a negative number will
move the piece up.deltaColumn - The number of columns to move this piece to the right; a negative
number will move the piece left.
public boolean moveTo(int newRow,
int newColumn)
newRow - The destination row.newColumn - The destination column.
false if the destination is not a legal board
position, or if the piece is already moving.
public boolean canMove(int deltaRow,
int deltaColumn)
true if this
piece is on a board and the location is legal for that board.
This method can be overridden with more specific tests.
deltaRow - The number of squares to move down.deltaColumn - The number of squares to move to the right.
true if the move can be made.
public boolean canMoveTo(int newRow,
int newColumn)
true if this
piece is on a board and the location is legal for that board.
This method can be overridden with more specific tests.
newRow - The desired row.newColumn - The desired column.
true if the move can be made.public void redraw()
public void redraw(java.awt.Rectangle rect)
rect - The area to be redrawn.public void dump()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||