📄 brick.java~8~
字号:
package pinball;import javax.microedition.lcdui.Graphics;/** * * <p>Title: 砖块</p> * * <p>Description: 该类实现了砖块的显示和属性的维护,包括砖块的类别,坐标等。 * 此外,该类还实现了砖块的自绘功能。</p> * */public class Brick extends Sprite { public static final int WIDTH = Screen.width / 15; public static final int HEIGHT = Screen.height / 30; public static final int STEP = Screen.width / 25; public static final int GAP = Math.max(2, Screen.width / 50); public static final int ZOMBIE = 0; public static final int STANDARD = 1; public static final int FIXED = 2; public static final int SLIDE = 3; private int pos; private int type; private ThreeDColor color; private ThreeDColor brighter; private ThreeDColor darker; private ThreeDColor[] color_list = { ThreeDColor.black, ThreeDColor.blue, ThreeDColor.green, ThreeDColor.darkGreen }; private int nScore; private BrickList owner; public Brick(BrickList owner, int x, int y, int pos, int type) { this.pos = pos; this.owner = owner; moveTo(x, y); if (type == ZOMBIE) { width = 0; height = 0; } else { width = WIDTH; height = HEIGHT; } this.type = type; color = color_list[type]; brighter = color.brighter(); darker = color.darker(); if (type == STANDARD) { nScore = 1; } } public Brick(Brick brick) { pos = brick.pos; owner = brick.owner; moveTo(brick.x, brick.y); type = brick.type; width = brick.width; height = brick.height; color = brick.color; brighter = brick.brighter; darker = brick.darker; nScore = brick.nScore; } public int getPos() { return pos; } public void setPos(int pos) { this.pos = pos; } public void setColor(ThreeDColor color) { this.color = color; brighter = color.brighter(); darker = color.darker(); } public void clear() { type = ZOMBIE; width = 0; height = 0; } public int hit(int direction) { if (type == STANDARD) { clear(); } if (type == SLIDE) { Brick neighbor = owner.getNeighbor(this, direction); if (neighbor != null && neighbor.getType() == 0) { owner.moveBrick(pos, neighbor.pos); } } return nScore; } public int getType() { return type; } public boolean isFixed() { return type == ZOMBIE || type == FIXED; } public void paint(Graphics g) { if (type == ZOMBIE) { return; } g.setColor(color.getRGB()); g.fillRect(x, y, width, height); g.setColor(brighter.getRGB()); g.drawLine(x, y, x + width, y); if (Screen.width >= 150) { g.drawLine(x, y + 1, x + width - 1, y + 1); } g.drawLine(x, y, x, y + height); if (Screen.height >= 150) { g.drawLine(x + 1, y, x + 1, y + height - 1); } g.setColor(darker.getRGB()); g.drawLine(x + width, y, x + width, y + height); if (Screen.height >= 150) { g.drawLine(x + width - 1, y + 1, x + width - 1, y + height); } g.drawLine(x, y + height, x + width, y + height); if (Screen.width >= 150) { g.drawLine(x + 1, y + height - 1, x + width, y + height - 1); } } public void paintShadow(Graphics g) { if (type == ZOMBIE) { return; } g.setColor(ThreeDColor.black.getRGB()); g.fillRect(x + shadow, y + shadow, width, height); } public void erase(Graphics g) { if (isFixed()) { return; } g.setColor(Screen.BACKGROUND); g.fillRect(x, y, width + shadow, height + shadow); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -