⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flower.java

📁 为解压缩文件
💻 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 + -