Page 876 - 2
P. 876

{
                    curPiece.setRandomShape();
                    curX = BoardWidth / 2 + 1;
                    curY = BoardHeight - 1 + curPiece.minY();


                    if (!tryMove(curPiece, curX, curY)) {
                        curPiece.setShape(Tetrominoes.NoShape);
                        timer.stop();
                        isStarted = false;
                        statusbar.setText("game over");
                    }
                }


                private boolean tryMove(Shape newPiece, int newX, int newY)
                {
                    for (int i = 0; i < 4; ++i) {
                        int x = newX + newPiece.x(i);
                        int y = newY - newPiece.y(i);
                        if (x < 0 || x >= BoardWidth || y < 0 || y >= BoardHeight)
                            return false;
                        if (shapeAt(x, y) != Tetrominoes.NoShape)
                            return false;
                    }


                    curPiece = newPiece;
                    curX = newX;
                    curY = newY;
                    repaint();
                    return true;
                }


                public void removeFullLines()
                {
                    int numFullLines = 0;


                    for (int i = BoardHeight - 1; i >= 0; --i) {
                        boolean lineIsFull = true;


                        for (int j = 0; j < BoardWidth; ++j) {
                            if (shapeAt(j, i) == Tetrominoes.NoShape) {
                                lineIsFull = false;
                                break;
                            }
                        }
                        if (lineIsFull) {


                                                         - 876 -
   871   872   873   874   875   876   877   878   879   880   881