📄 square.java
字号:
package eric.block;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display;
/**
* Class/Interface description an seqerate cute
*
* @author Eric
* @see Another Class
* @since 0.1
*/
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;
/**
* @param x
* @param y
* @param blockType
* @param display
*/
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, 255, 255, 255);
}
// Get color from block type
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
// Backgroud color
return new Color(display, 0, 0, 0);
}
/**
* set block border color
* @param color
*/
public void setBorderColor(Color color)
{
this.borderColor = color;
}
/**
* Draw small block
*/
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 + -