Page 870 - 2
P. 870

}
            }


            STEP2. Tetris  게임 중 블록의 외형과 블록이 떨어질 때의 좌표 값을 정의한 클래스,
            Shape.class
            package tetris;


            import java.util.Random;
            import java.lang.Math;




            public class Shape {


                enum Tetrominoes { NoShape, ZShape, SShape, LineShape,
                           TShape, SquareShape, LShape, MirroredLShape };


                private Tetrominoes pieceShape;
                private int coords[][];
                private int[][][] coordsTable;




                public Shape() {


                    coords = new int[4][2];
                    setShape(Tetrominoes.NoShape);


                }


                public void setShape(Tetrominoes shape) {


                     coordsTable = new int[][][] {
                        { { 0, 0 },  { 0, 0 },  { 0, 0 },  { 0, 0 } },
                        { { 0, -1 }, { 0, 0 },  { -1, 0 }, { -1, 1 } },
                        { { 0, -1 }, { 0, 0 },  { 1, 0 },  { 1, 1 } },
                        { { 0, -1 }, { 0, 0 },  { 0, 1 },  { 0, 2 } },
                        { { -1, 0 }, { 0, 0 },  { 1, 0 },  { 0, 1 } },
                        { { 0, 0 },  { 1, 0 },  { 0, 1 },  { 1, 1 } },
                        { { -1, -1 }, { 0, -1 }, { 0, 0 },  { 0, 1 } },
                        { { 1, -1 }, { 0, -1 }, { 0, 0 },  { 0, 1 } }
                    };


                    for (int i = 0; i < 4 ; i++) {
                        for (int j = 0; j < 2; ++j) {
                            coords[i][j] = coordsTable[shape.ordinal()][i][j];
                        }


                                                         - 870 -
   865   866   867   868   869   870   871   872   873   874   875