|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcs1705.tetris.Board
Represents a Tetris board -- essentially a 2-d grid of booleans. Supports tetris pieces and row clearning. Has an "undo" feature that allows clients to add and remove pieces efficiently. Does not do any drawing or have any idea of pixels. Intead, just represents the abstract 2-d board.
| Field Summary | |
static int |
PLACE_BAD
|
static int |
PLACE_OK
|
static int |
PLACE_OUT_BOUNDS
|
static int |
PLACE_ROW_FILLED
|
| Constructor Summary | |
Board(int aWidth,
int aHeight)
Creates an empty board of the given width and height measured in blocks. |
|
Board(int aWidth,
int aHeight,
String[] rows)
Creates a board of the given width and height measured in blocks, and then populates it with the blocks indicated by the given string array. |
|
| Method Summary | |
int |
apply(Move move)
Attempts to add apply the given move to the board. |
boolean |
clearRows()
Deletes rows that are filled all the way across, moving things above down. |
void |
commit()
Puts the board in the committed state. |
boolean |
equals(Object other)
Returns true if two boards are the same, meaning they have blocks in exactly the same locations. |
int |
getBlocksInRow(int y)
Returns the number of filled blocks in the given row. |
int |
getColumnHeight(int x)
Returns the height of the given column, which is the y value of the highest block + 1. |
int |
getHeight()
Returns the height of the board in blocks. |
int |
getLargestHeight()
Returns the max column height present in the board. |
int |
getWidth()
Returns the width of the board in blocks. |
boolean |
hasBlockAt(int x,
int y)
Returns true if the given block is filled in the board. |
int |
place(Piece piece,
int x,
int y)
Attempts to add the body of a piece to the board. |
int |
rowAfterDrop(Piece piece,
int x)
Given a piece and an x, returns the y value where the piece would come to rest if it were dropped straight down at that x. |
void |
sanityCheck()
Checks the board for internal consistency -- used for debugging. |
String |
toString()
Returns a human-readable string representation of this board. |
void |
undo()
If a place() happens, optionally followed by a clearRows(), a subsequent undo() reverts the board to its state before the place(). |
| Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int PLACE_BAD
public static final int PLACE_OK
public static final int PLACE_OUT_BOUNDS
public static final int PLACE_ROW_FILLED
| Constructor Detail |
public Board(int aWidth,
int aHeight)
public Board(int aWidth,
int aHeight,
String[] rows)
| Method Detail |
public int apply(Move move)
public boolean clearRows()
public void commit()
public boolean equals(Object other)
public int getBlocksInRow(int y)
public int getColumnHeight(int x)
public int getHeight()
public int getLargestHeight()
public int getWidth()
public final boolean hasBlockAt(int x,
int y)
public int place(Piece piece,
int x,
int y)
Error cases:
If part of the piece would fall out of bounds, the placement
does not change the board at all, and PLACE_OUT_BOUNDS is returned.
If the placement is "bad"--interfering with existing blocks in the
grid--then the placement is halted partially complete and PLACE_BAD
is returned.
An undo() will remove the bad placement.
public int rowAfterDrop(Piece piece,
int x)
public void sanityCheck()
public String toString()
getLargestHeight()
are printed, including the lowest blank row just before the
highest block on the board.
public void undo()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||