?? flower.java
字號:
package pangxie;
import javax.microedition.lcdui.*;
import java.util.Timer;
import java.util.TimerTask;
class Flower {
boolean bug;
boolean b = false;
static Image image[] = new Image[2];
GameLogic logic;
java.util.Timer timer;
public static final int OraginRate = 3;
int rate = OraginRate;
int power;
int x, y, originx, originy;
GameCanvas gc;
byte baoReleasedPermission;
static {
try {
image[0] = Image.createImage("/res/f.png");
image[1] = Image.createImage("/res/ff.png");
} catch (Exception ex) {
}
}
public Flower(int xx, int yy, GameLogic logic) {
this.originx = this.x = xx;
this.originy = this.y = yy;
this.logic = logic;
}
public void paint(Graphics g) {
g.drawImage(image[0], x, y + 31, Graphics.LEFT | Graphics.TOP);
if (b == true) {
g.drawImage(image[1], x, y + 31, Graphics.LEFT | Graphics.TOP);
}
}
public void fall() {
timer = new Timer();
timer.schedule(new FallTask(), 0, GameLogic.Delay);
}
public void stopFall() {
timer.cancel();
timer = null;
System.gc();
}
public boolean crash(PangXie px) {
//px左上角點坐標
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 15; j++) {
for (int k = 0; k < 15; k++) {
if (x + j >= px.x + i && x + j <= px.x + k && y + j >= px.y &&
y + j <= px.y + k) {
b = true;
}
if (x + j <= px.x + i && x + j >= px.x + k && y + j <= px.y &&
y + j >= px.y + k) {
b = true;
}
}
}
}
return b;
}
class FallTask extends TimerTask {
int count = 0;
public void run() {
y += rate;
count++;
if (count % 2 == 0) {
rate += 4;
}
for (int i = 0; i < logic.gc.pangs.size(); i++) {
PangXie px = (PangXie) logic.gc.pangs.elementAt(i);
if (crash(px) && power > 1 && power <= 100) {
if (baoReleasedPermission == 1) {
logic.bingo(px, Flower.this);
break;
}
} else if (crash(px) && power == 1) {
logic.bingo(px, Flower.this);
power--;
break;
}
}
if (y > GameCanvas.h) {
baoReleasedPermission = 0;
if (y > GameCanvas.h + 150) {
power = 1;
stopFall();
count = 0;
x = originx;
y = originy;
rate = OraginRate;
b = false;
}
}
logic.gc.repaint();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -