public void setBoard (Board board)
{
// when a new board arrives, we want to remove all drop sprites
// so that they don't modify the new board with their old ideas
for (Iterator<Sprite> iter = _actionSprites.iterator(); iter.hasNext(); ) {
Sprite s = iter.next();
if (s instanceof DropSprite) {
// remove it from _sprites safely
iter.remove();
// but then use the standard removal method
removeSprite(s);
}
}
// remove all of this board's piece sprites
int pcount = (_pieces == null) ? 0 : _pieces.length;
for (int ii = 0; ii < pcount; ii++) {
if (_pieces[ii] != null) {
removeSprite(_pieces[ii]);
}
}
super.setBoard(board);
_dboard = (DropBoard)board;
// create the pieces for the new board
Point spos = new Point();
int width = _dboard.getWidth(), height = _dboard.getHeight();
_pieces = new Sprite[width * height];
for (int yy = 0; yy < height; yy++) {
for (int xx = 0; xx < width; xx++) {
Sprite piece = createPieceSprite(_dboard.getPiece(xx, yy), xx, yy);
if (piece != null) {
int ppos = yy * width + xx;
getPiecePosition(xx, yy, spos);
piece.setLocation(spos.x, spos.y);
addSprite(piece);
_pieces[ppos] = piece;
}
}
}