📄 shape.java
字号:
import javax.microedition.lcdui.Graphics;
public class Shape
{
private ShapeListener listener;
private int[][] body;
private int status;
private int left;
private int top;
public static final int ROTATE = 1;
public static final int DOWN = 2;
public static final int LEFT = 3;
public static final int RIGHT = 4;
public int getLeft(){return left;}
public int getTop(){return top;}
public Shape()
{
new Thread(new ShapDriver()).start();
}
public void rotate()
{
System.out.println("rect rotate");
status = (status + 1)%body.length;
}
public void moveDown()
{
System.out.println("rect move down");
top++;
}
public void moveLeft()
{
System.out.println("rect move left");
left--;
}
public void moveRight()
{
System.out.println("rect move right");
left++;
}
public void addListener(ShapeListener lis)
{
listener = lis;
}
public static final int CELL_SIZE = 20;
public void paint(Graphics g)
{
System.out.println("Shape`s paint");
g.setColor(0xFF0000);
for(int x=0; x<4; x++)
{
for(int y=0; y<4; y++)
{
if(getFlagByPoint(x, y))
{
g.fillRoundRect((left+x)*CELL_SIZE,
(top+y)*CELL_SIZE,CELL_SIZE,CELL_SIZE,5,5);
}
}
}
}
private boolean getFlagByPoint(int x, int y)
{
return body[status][y*4+x] == 1;
}
public boolean isMember(int x, int y, boolean rotate)
{
int tmpStatus = status;
if(rotate)
{
tmpStatus = (tmpStatus+1)%body.length;
}
return body[tmpStatus][y*4+x] == 1;
}
public void setStatus(int status)
{
this.status = status;
}
public void setBody(int[][] body)
{
this.body = body;
}
private class ShapDriver implements Runnable
{
public void run()
{
while(listener.isShapeMoveable(Shape.this))
{
moveDown();
listener.shapeMoveDown(Shape.this);
try{Thread.sleep(1000);}catch(Exception e){}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -