📄 shape.java
字号:
import javax.microedition.lcdui.*;
public final class Shape {
private static final int[] NEXT = { 0, 2, 1, 4, 5,
6, 3, 8, 9, 10,
7, 12, 13, 14, 11,
16, 15, 18, 17
};
private static final int[] INIT_TOP = {-1, -1, 0, 0, -1,
0, 0, 0, 0, 0,
-1, 0, 0, -1, 0,
-1, 0, -1, 0
};
public static final Shape[] SHAPES = {
new Shape(0, new int[]{0,0,0,0,
0,1,1,0,
0,1,1,0,
0,0,0,0}),
new Shape(1, new int[]{0,0,0,0,
1,1,1,1,
0,0,0,0,
0,0,0,0}),
new Shape(2, new int[]{0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0}),
new Shape(3, new int[]{0,1,0,0,
0,1,0,0,
0,1,1,0,
0,0,0,0}),
new Shape(4, new int[]{0,0,0,0,
1,1,1,0,
1,0,0,0,
0,0,0,0}),
new Shape(5, new int[]{1,1,0,0,
0,1,0,0,
0,1,0,0,
0,0,0,0}),
new Shape(6, new int[]{0,0,1,0,
1,1,1,0,
0,0,0,0,
0,0,0,0}),
new Shape(7, new int[]{0,1,0,0,
0,1,0,0,
1,1,0,0,
0,0,0,0}),
new Shape(8, new int[]{1,0,0,0,
1,1,1,0,
0,0,0,0,
0,0,0,0}),
new Shape(9, new int[]{0,1,1,0,
0,1,0,0,
0,1,0,0,
0,0,0,0}),
new Shape(10, new int[]{0,0,0,0,
1,1,1,0,
0,0,1,0,
0,0,0,0}),
new Shape(11, new int[]{0,1,0,0,
1,1,1,0,
0,0,0,0,
0,0,0,0}),
new Shape(12, new int[]{0,1,0,0,
0,1,1,0,
0,1,0,0,
0,0,0,0}),
new Shape(13, new int[]{0,0,0,0,
1,1,1,0,
0,1,0,0,
0,0,0,0}),
new Shape(14, new int[]{0,1,0,0,
1,1,0,0,
0,1,0,0,
0,0,0,0}),
new Shape(15, new int[]{0,0,0,0,
0,1,1,0,
1,1,0,0,
0,0,0,0}),
new Shape(16, new int[]{0,1,0,0,
0,1,1,0,
0,0,1,0,
0,0,0,0}),
new Shape(17, new int[]{0,0,0,0,
1,1,0,0,
0,1,1,0,
0,0,0,0}),
new Shape(18, new int[]{0,0,1,0,
0,1,1,0,
0,1,0,0,
0,0,0,0})
};
private int index;
private int[] data;
private Shape(final int index, final int[] data) {
this.index = index;
this.data = data;
}
public int getIndex() { return index; }
public int getWidth() { return 4; }
public int getHeight() { return 4; }
public int[] getData() { return data; }
public Shape next() { return SHAPES[NEXT[index]]; }
static int getInitTop(int index) {
return INIT_TOP[index];
}
public void paint(Graphics g, int box_size, int color) {
for(int i=0; i<4; i++) {
for(int j=0; j<4; j++) {
if(data[4*j+i]==1) {
g.setColor(MyCanvas.BORDER_COLOR);
g.drawRect(i*box_size, j*box_size, box_size, box_size);
g.setColor(color);
g.fillRect(i*box_size+1, j*box_size+1, box_size-2, box_size-2);
}
}
}
}
public void erase(Graphics g, int box_size) {
for(int i=0; i<4; i++) {
for(int j=0; j<4; j++) {
if(data[4*j+i]==1) {
g.setColor(0);
g.drawRect(i*box_size, j*box_size, box_size, box_size);
g.fillRect(i*box_size, j*box_size, box_size, box_size);
}
}
}
}
public static int indexOf(Shape shape) {
for(int i=0; i<SHAPES.length; i++) {
if(SHAPES[i]==shape) return i;
}
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -