Android Open Source - Tetris_android Rotation Manager






From Project

Back to project page Tetris_android.

License

The source code is released under:

GNU General Public License

If you think the Android project Tetris_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.tiphedor.tetris;
//  ww  w . j  av a  2  s.c  o m
/**
 * Detection of the validity of rotations
 *
 * @author tiphedor
 */

public class RotationManager {

    /**
     * Destination of the rotating piece
     */
    private Coordinate pieceDestination;

    /**
     * Constructor of the class
     * @param mPieceDestination destination of the piece
     */
    public RotationManager(Coordinate mPieceDestination) {
        this.pieceDestination = mPieceDestination;
    }

    /**
     * Check if a rotation is possible
     * @return Possibility of rotation
     */
    public boolean checkRotationValidity() {
        // Detect if rotation will put a part of the piece out of the board
        if(pieceDestination.getX1() < 0 || pieceDestination.getX1() > 9
                || pieceDestination.getX2() < 0 || pieceDestination.getX2() > 9
                || pieceDestination.getX3() < 0 || pieceDestination.getX3() > 9
                || pieceDestination.getX4() < 0 || pieceDestination.getX4() > 9

                || pieceDestination.getY1() < 0 || pieceDestination.getY1() > 21
                || pieceDestination.getY2() < 0 || pieceDestination.getY2() > 21
                || pieceDestination.getY3() < 0 || pieceDestination.getY3() > 21
                || pieceDestination.getY4() < 0 || pieceDestination.getY4() > 21) {
            return false;
        }

        // Detect if rotation don't make the piece go on other pieces
        // @todo

        return true;
    }
}




Java Source Code List

fr.tiphedor.tetris.CollisionManager.java
fr.tiphedor.tetris.Coordinate.java
fr.tiphedor.tetris.GameActivity.java
fr.tiphedor.tetris.MenuActivity.java
fr.tiphedor.tetris.Piece.java
fr.tiphedor.tetris.RotationManager.java
fr.tiphedor.tetris.TetrisView.java