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
|
* for checking things like whether the game is over, whether a player is
|
||||||
* still active in the game, and so forth.
|
* still active in the game, and so forth.
|
||||||
*
|
*
|
||||||
* <p> Derived classes are likely to want to override {@link
|
* <p> Derived classes are likely to want to override {@link #getPieceDropLogic}.
|
||||||
* #getPieceDropLogic}.
|
|
||||||
*/
|
*/
|
||||||
public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
public abstract class DropManagerDelegate extends PuzzleManagerDelegate
|
||||||
implements PuzzleCodes, DropCodes
|
implements PuzzleCodes, DropCodes
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ public interface PieceDropLogic
|
|||||||
public boolean isDroppablePiece (int piece);
|
public boolean isDroppablePiece (int piece);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the given piece has constraints upon it that
|
* Returns whether the given piece has constraints upon it that impact its droppability.
|
||||||
* impact its droppability.
|
|
||||||
*/
|
*/
|
||||||
public boolean isConstrainedPiece (int piece);
|
public boolean isConstrainedPiece (int piece);
|
||||||
|
|
||||||
@@ -59,16 +58,13 @@ public interface PieceDropLogic
|
|||||||
* @param pre whether the climbability check is being performed
|
* @param pre whether the climbability check is being performed
|
||||||
* before the height is incremented, or after.
|
* before the height is incremented, or after.
|
||||||
*/
|
*/
|
||||||
public boolean isClimbablePiece (
|
public boolean isClimbablePiece (boolean allowConst, int piece, boolean pre);
|
||||||
boolean allowConst, int piece, boolean pre);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the x-axis coordinate of the specified edge of the
|
* Returns the x-axis coordinate of the specified edge of the given constrained piece.
|
||||||
* given constrained piece.
|
|
||||||
*
|
*
|
||||||
* <p> TODO: This should go away once the sword and sail games
|
* <p> TODO: This should go away once the sword and sail games have standardized on
|
||||||
* have standardized on WEST/EAST or BLOCK_LEFT/BLOCK_RIGHT to
|
* WEST/EAST or BLOCK_LEFT/BLOCK_RIGHT to reference block edges.
|
||||||
* reference block edges.
|
|
||||||
*
|
*
|
||||||
* @param board the board to search.
|
* @param board the board to search.
|
||||||
* @param col the column of the constrained piece.
|
* @param col the column of the constrained piece.
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ public class PieceDropper
|
|||||||
implements DropPieceCodes
|
implements DropPieceCodes
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A class to hold information detailing the pieces to be dropped
|
* A class to hold information detailing the pieces to be dropped in a particular column.
|
||||||
* in a particular column.
|
|
||||||
*/
|
*/
|
||||||
public static class PieceDropInfo
|
public static class PieceDropInfo
|
||||||
{
|
{
|
||||||
@@ -92,8 +91,7 @@ public class PieceDropper
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Effects any drops possible on the supplied board (modifying the
|
* Effects any drops possible on the supplied board (modifying the
|
||||||
* board in the progress) and notifying the supplied drop observer of
|
* board in the progress) and notifying the supplied drop observer of those drops.
|
||||||
* those drops.
|
|
||||||
*
|
*
|
||||||
* @return the number of pieces dropped.
|
* @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
|
// if the board wants pieces to be dropped in to fill the gaps, do that now
|
||||||
// that now
|
|
||||||
if (_logic.boardAlwaysFilled()) {
|
if (_logic.boardAlwaysFilled()) {
|
||||||
for (int xx = 0; xx < bwid; xx++) {
|
dropped += fillBoard(board, drobs);
|
||||||
int dist = board.getDropDistance(xx, -1);
|
}
|
||||||
for (int ii = 0; ii < dist; ii++) {
|
|
||||||
int yy = (-1 - ii);
|
return dropped;
|
||||||
int piece = board.getNextPiece();
|
}
|
||||||
if (piece != PIECE_NONE) {
|
|
||||||
drop(board, piece, xx, yy, yy + dist, drobs);
|
/**
|
||||||
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
|
* Computes and effects the drop for the specified piece and any
|
||||||
* associated attached pieces. The supplied observer is notified of
|
* associated attached pieces. The supplied observer is notified of all drops.
|
||||||
* all drops.
|
|
||||||
*/
|
*/
|
||||||
protected int dropPieces (
|
protected int dropPieces (DropBoard board, int xx, int yy, DropObserver drobs)
|
||||||
DropBoard board, int xx, int yy, DropObserver drobs)
|
|
||||||
{
|
{
|
||||||
// skip empty or fixed pieces
|
// skip empty or fixed pieces
|
||||||
int piece = board.getPiece(xx, yy);
|
int piece = board.getPiece(xx, yy);
|
||||||
@@ -147,8 +157,7 @@ public class PieceDropper
|
|||||||
int bwid = board.getWidth();
|
int bwid = board.getWidth();
|
||||||
if (start < 0 || end >= bwid) {
|
if (start < 0 || end >= bwid) {
|
||||||
Log.warning("Board reported bogus constrained edge " +
|
Log.warning("Board reported bogus constrained edge " +
|
||||||
"[x=" + xx + ", y=" + yy +
|
"[x=" + xx + ", y=" + yy + ", start=" + start + ", end=" + end + "].");
|
||||||
", start=" + start + ", end=" + end + "].");
|
|
||||||
board.dump();
|
board.dump();
|
||||||
start = Math.max(start, 0);
|
start = Math.max(start, 0);
|
||||||
end = Math.min(end, bwid);
|
end = Math.min(end, bwid);
|
||||||
|
|||||||
Reference in New Issue
Block a user