Widen up some drop puzzle code, and break the board filling action out into
its own function so puzzles wanting fancier fill logic can override it as needed. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@370 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -58,8 +58,7 @@ import com.threerings.puzzle.drop.util.PieceDropper;
|
||||
* for checking things like whether the game is over, whether a player is
|
||||
* still active in the game, and so forth.
|
||||
*
|
||||
* <p> Derived classes are likely to want to override {@link
|
||||
* #getPieceDropLogic}.
|
||||
* <p> Derived classes are likely to want to override {@link #getPieceDropLogic}.
|
||||
*/
|
||||
public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
||||
implements PuzzleCodes, DropCodes
|
||||
|
||||
@@ -44,8 +44,7 @@ public interface PieceDropLogic
|
||||
public boolean isDroppablePiece (int piece);
|
||||
|
||||
/**
|
||||
* Returns whether the given piece has constraints upon it that
|
||||
* impact its droppability.
|
||||
* Returns whether the given piece has constraints upon it that impact its droppability.
|
||||
*/
|
||||
public boolean isConstrainedPiece (int piece);
|
||||
|
||||
@@ -59,16 +58,13 @@ public interface PieceDropLogic
|
||||
* @param pre whether the climbability check is being performed
|
||||
* before the height is incremented, or after.
|
||||
*/
|
||||
public boolean isClimbablePiece (
|
||||
boolean allowConst, int piece, boolean pre);
|
||||
public boolean isClimbablePiece (boolean allowConst, int piece, boolean pre);
|
||||
|
||||
/**
|
||||
* Returns the x-axis coordinate of the specified edge of the
|
||||
* given constrained piece.
|
||||
* Returns the x-axis coordinate of the specified edge of the given constrained piece.
|
||||
*
|
||||
* <p> TODO: This should go away once the sword and sail games
|
||||
* have standardized on WEST/EAST or BLOCK_LEFT/BLOCK_RIGHT to
|
||||
* reference block edges.
|
||||
* <p> TODO: This should go away once the sword and sail games have standardized on
|
||||
* WEST/EAST or BLOCK_LEFT/BLOCK_RIGHT to reference block edges.
|
||||
*
|
||||
* @param board the board to search.
|
||||
* @param col the column of the constrained piece.
|
||||
|
||||
@@ -38,8 +38,7 @@ public class PieceDropper
|
||||
implements DropPieceCodes
|
||||
{
|
||||
/**
|
||||
* A class to hold information detailing the pieces to be dropped
|
||||
* in a particular column.
|
||||
* A class to hold information detailing the pieces to be dropped in a particular column.
|
||||
*/
|
||||
public static class PieceDropInfo
|
||||
{
|
||||
@@ -92,8 +91,7 @@ public class PieceDropper
|
||||
|
||||
/**
|
||||
* Effects any drops possible on the supplied board (modifying the
|
||||
* board in the progress) and notifying the supplied drop observer of
|
||||
* those drops.
|
||||
* board in the progress) and notifying the supplied drop observer of those drops.
|
||||
*
|
||||
* @return the number of pieces dropped.
|
||||
*/
|
||||
@@ -106,18 +104,32 @@ public class PieceDropper
|
||||
}
|
||||
}
|
||||
|
||||
// if the board wants pieces to be dropped in to fill the gaps, do
|
||||
// that now
|
||||
// if the board wants pieces to be dropped in to fill the gaps, do that now
|
||||
if (_logic.boardAlwaysFilled()) {
|
||||
for (int xx = 0; xx < bwid; xx++) {
|
||||
int dist = board.getDropDistance(xx, -1);
|
||||
for (int ii = 0; ii < dist; ii++) {
|
||||
int yy = (-1 - ii);
|
||||
int piece = board.getNextPiece();
|
||||
if (piece != PIECE_NONE) {
|
||||
drop(board, piece, xx, yy, yy + dist, drobs);
|
||||
dropped++;
|
||||
}
|
||||
dropped += fillBoard(board, drobs);
|
||||
}
|
||||
|
||||
return dropped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops new pieces onto the board to fill the gaps.
|
||||
*
|
||||
* @return the number of pieces dropped.
|
||||
*/
|
||||
public int fillBoard (DropBoard board, DropObserver drobs)
|
||||
{
|
||||
int dropped = 0;
|
||||
int bwid = board.getWidth();
|
||||
|
||||
for (int xx = 0; xx < bwid; xx++) {
|
||||
int dist = board.getDropDistance(xx, -1);
|
||||
for (int ii = 0; ii < dist; ii++) {
|
||||
int yy = (-1 - ii);
|
||||
int piece = board.getNextPiece();
|
||||
if (piece != PIECE_NONE) {
|
||||
drop(board, piece, xx, yy, yy + dist, drobs);
|
||||
dropped++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,11 +139,9 @@ public class PieceDropper
|
||||
|
||||
/**
|
||||
* Computes and effects the drop for the specified piece and any
|
||||
* associated attached pieces. The supplied observer is notified of
|
||||
* all drops.
|
||||
* associated attached pieces. The supplied observer is notified of all drops.
|
||||
*/
|
||||
protected int dropPieces (
|
||||
DropBoard board, int xx, int yy, DropObserver drobs)
|
||||
protected int dropPieces (DropBoard board, int xx, int yy, DropObserver drobs)
|
||||
{
|
||||
// skip empty or fixed pieces
|
||||
int piece = board.getPiece(xx, yy);
|
||||
@@ -147,8 +157,7 @@ public class PieceDropper
|
||||
int bwid = board.getWidth();
|
||||
if (start < 0 || end >= bwid) {
|
||||
Log.warning("Board reported bogus constrained edge " +
|
||||
"[x=" + xx + ", y=" + yy +
|
||||
", start=" + start + ", end=" + end + "].");
|
||||
"[x=" + xx + ", y=" + yy + ", start=" + start + ", end=" + end + "].");
|
||||
board.dump();
|
||||
start = Math.max(start, 0);
|
||||
end = Math.min(end, bwid);
|
||||
|
||||
Reference in New Issue
Block a user