问题
Ok, so I am trying to do this tutorial: http://mathcs.slu.edu/~fritts/cse131/labs/lab9/index.html
But I don't know how to rotate objects
synchronized void moveDown() {
}
Is there any defined method for that or do I have to implement my own code? I thought about changing the shape of the object, but that would imply I have to change my current object every time, which might be a little complicated to implement.
The method that calls 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();
}
}
I was about to add L1a, L1b, L1c, etc. Isn't there any other way?
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}
};
来源:https://stackoverflow.com/questions/14867570/rotating-objects-in-a-grid-gui-java-swing