在网格中旋转对象(GUI,JAVA SWING)

时间:2013-02-14 03:58:29

标签: java swing user-interface 2d

好的,我正在尝试做这个教程:http://mathcs.slu.edu/~fritts/cse131/labs/lab9/index.html

但我不知道如何旋转物体

synchronized void moveDown() {

}

是否有任何已定义的方法或我是否必须实现自己的代码?我想改变对象的形状,但这意味着我每次都要改变当前的对象,这可能有点复杂。

调用moveDown的方法:

public void keyPressed(KeyEvent event) {
        int key = event.getKeyCode();
        switch (key) {
        case KeyEvent.VK_UP:  // up arrow
        case KeyEvent.VK_KP_UP:
            currentPiece.rotateCounterclockwise();
            break;
        case KeyEvent.VK_DOWN:  // down arrow
        case KeyEvent.VK_KP_DOWN:
            currentPiece.rotateClockwise();
            break;
        case KeyEvent.VK_LEFT:  // left arrow
        case KeyEvent.VK_KP_LEFT:
            currentPiece.moveLeft();
            break;
        case KeyEvent.VK_RIGHT:  // right arrow
        case KeyEvent.VK_KP_RIGHT:
            currentPiece.moveRight();
            break;
        case KeyEvent.VK_SPACE:  //  space bar
            currentPiece.drop();
        }
    }

我准备添加L1a,L1b,L1c等。还有其他方法吗?

    public static final int[][] L1 =
    {{1,1},
     {0,1},
     {0,1}
    };

public static final int[][] L2 =
    {{0,1},
     {0,1},
     {1,1}
    };      

public static final int[][] T =
    {{0,1},
     {1,1},
     {0,1}
    };

public static final int[][] BOX =
    {{1,1},
     {1,1}
    };

public static final int[][] BAR =
    {{1,1,1,1}
    };      

public static final int[][] STEP1 =
    {{1,0},
     {1,1},
     {0,1}
    };  

public static final int[][] STEP2 =
    {{0,1},
     {1,1},
     {1,0}
    };

0 个答案:

没有答案