📄 square.java
字号:
package xn.tetris;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display;
/**
* 组成各种造型方块的小方块类
* 一个小方块长和宽均为30象素
* */
public class Square {
private int x;
private int y;
private Color squareColor;
private Color borderColor;
private int blockType;
private GC gc;
private Display display;
final static int LENGTH = 30;
public Square(int x, int y, int blockType, Display display){
this.x = x;
this.y = y;
this.blockType = blockType;
this.display = display;
borderColor = new Color(display, 0, 0, 0);
}
//根据block的类型得到当前小方块的颜色
private Color getSquareColor(){
//L_BLOCK
if(blockType >=0 && blockType <= 3){
return new Color(display, 66, 232, 211);
}
//J_BLOCK
else if(blockType >= 10 && blockType <= 13){
return new Color(display, 243, 136, 219);
}
//I_BLOCK
else if(blockType == 20 || blockType == 21){
return new Color(display, 105, 206, 244);
}
//Z_BLOCK
else if(blockType == 30 || blockType == 31){
return new Color(display, 242, 146, 83);
}
//S_BLOCK
else if(blockType == 40 || blockType == 41){
return new Color(display, 243, 241, 101);
}
//O_BLOCK
else if(blockType == 50){
return new Color(display, 225, 102, 240);
}
//T_BLOCK
else if(blockType >= 60 && blockType <= 63){
return new Color(display, 102, 218, 151);
}
else//画成背景色
return new Color(display, 0, 0, 0);
}
//主要用于block类的clear方法中,将边框颜色设为黑色
/*public void setBorderColor(Color color){
this.borderColor = color;
}*/
//画出小方块
public void draw(){
squareColor = getSquareColor();
gc = MyGC.getMyGC();
gc.setBackground(squareColor);
gc.fillRectangle(x + 1, y + 1, 29, 29);
gc.setForeground(borderColor);
gc.drawLine(x, y, x + 30, y);
gc.drawLine(x + 30, y, x + 30, y + 30);
gc.drawLine(x + 30, y + 30, x, y + 30);
gc.drawLine(x, y + 30, x, y);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -