| Modifier and Type | Field and Description |
|---|---|
protected char[][] |
board
character representation of board
|
protected char |
displayChar
character representing piece
|
protected int |
leftCol
piece leftmost column
|
protected int |
size
piece dimension
|
protected int |
topRow
piece topmost row
|
| Constructor and Description |
|---|
Piece(char[][] board,
char displayChar,
int size,
int topRow,
int leftCol) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canMoveDir(Direction dir)
Return whether or not the piece is, in general, permitted to move in the given direction.
|
abstract int |
getBottomRow()
Return the row of the piece's bottom right corner.
|
int |
getLeftCol()
Return the leftmost column of the piece.
|
abstract int |
getRightCol()
Return the column of the piece's bottom right corner.
|
int |
getTopRow()
Return the top row of the piece.
|
java.lang.String |
toString()
Return a String with the single display character for the piece.
|
boolean |
tryMove(Direction dir)
Attempt a piece movement in a given direction, returning true or false depending on whether or not the move was successful.
|
protected char[][] board
protected char displayChar
protected int size
protected int topRow
protected int leftCol
public Piece(char[][] board,
char displayChar,
int size,
int topRow,
int leftCol)
board - a reference to the RandomRailroadRushHour char[][] board object common to all piecesdisplayChar - the character used to "paint" the piece on the board representationsize - the size of the piece. For up/down- or left/right-moving train pieces (with width 1), this is the piece length in grid squares.
For left/right/up/down-moving platform pieces, this is the size length in grid squares.topRow - the row of the piece's top left cornerleftCol - the column of the piece's top left cornerpublic int getTopRow()
public int getLeftCol()
public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public boolean tryMove(Direction dir)
dir - given direction of attempted movementpublic abstract int getBottomRow()
public abstract int getRightCol()
public boolean canMoveDir(Direction dir)
dir - given direction of movement