[
  {
    "path": ".classpath",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<classpath>\n\t<classpathentry kind=\"src\" path=\"src\"/>\n\t<classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6\"/>\n\t<classpathentry kind=\"output\" path=\"bin\"/>\n</classpath>\n"
  },
  {
    "path": ".project",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<projectDescription>\n\t<name>Shoot</name>\n\t<comment></comment>\n\t<projects>\n\t</projects>\n\t<buildSpec>\n\t\t<buildCommand>\n\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t</buildSpec>\n\t<natures>\n\t\t<nature>org.eclipse.jdt.core.javanature</nature>\n\t</natures>\n</projectDescription>\n"
  },
  {
    "path": ".settings/org.eclipse.jdt.core.prefs",
    "content": "#Mon Jul 21 11:48:12 CST 2014\neclipse.preferences.version=1\norg.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\norg.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\norg.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve\norg.eclipse.jdt.core.compiler.compliance=1.6\norg.eclipse.jdt.core.compiler.debug.lineNumber=generate\norg.eclipse.jdt.core.compiler.debug.localVariable=generate\norg.eclipse.jdt.core.compiler.debug.sourceFile=generate\norg.eclipse.jdt.core.compiler.problem.assertIdentifier=error\norg.eclipse.jdt.core.compiler.problem.enumIdentifier=error\norg.eclipse.jdt.core.compiler.source=1.6\n"
  },
  {
    "path": "README.md",
    "content": "![](http://wblearn.github.io/img/in-post/public/2556999-1a2ad6a9a6690588.gif)\n\n## 写在前面\n\n技术源于分享，所以今天抽空把自己之前用java做过的小游戏整理贴出来给大家参考学习。java确实不适合写桌面应用，这里只是**通过这个游戏让大家理解oop面向对象编程的过程**，纯属娱乐。代码写的很简单，也很容易理解，并且注释写的很清楚了，还有问题，自己私下去补课学习。\n\n## 完整代码\n\n>敌飞机\n\n\n```\nimport java.util.Random;\n\n\n 敌飞机: 是飞行物，也是敌人\n \npublic class Airplane extends FlyingObject implements Enemy {\n\tprivate int speed = 3;  //移动步骤\n\t\n\t/** 初始化数据 */\n\tpublic Airplane(){\n\t\tthis.image = ShootGame.airplane;\n\t\twidth = image.getWidth();\n\t\theight = image.getHeight();\n\t\ty = -height;          \n\t\tRandom rand = new Random();\n\t\tx = rand.nextInt(ShootGame.WIDTH - width);\n\t}\n\t\n\t/** 获取分数 */\n\t@Override\n\tpublic int getScore() {  \n\t\treturn 5;\n\t}\n\n\t/** //越界处理 */\n\t@Override\n\tpublic \tboolean outOfBounds() {   \n\t\treturn y>ShootGame.HEIGHT;\n\t}\n\n\t/** 移动 */\n\t@Override\n\tpublic void step() {   \n\t\ty += speed;\n\t}\n\n}\n\n```\n\n>分数奖励\n\n```\n/** \n * 奖励 \n */  \npublic interface Award {  \n    int DOUBLE_FIRE = 0;  //双倍火力  \n    int LIFE = 1;   //1条命  \n    /** 获得奖励类型(上面的0或1) */  \n    int getType();  \n}  \n```\n\n>蜜蜂\n\n```\nimport java.util.Random;  \n  \n/** 蜜蜂 */  \npublic class Bee extends FlyingObject implements Award{  \n    private int xSpeed = 1;   //x坐标移动速度  \n    private int ySpeed = 2;   //y坐标移动速度  \n    private int awardType;    //奖励类型  \n      \n    /** 初始化数据 */  \n    public Bee(){  \n        this.image = ShootGame.bee;  \n        width = image.getWidth();  \n        height = image.getHeight();  \n        y = -height;  \n        Random rand = new Random();  \n        x = rand.nextInt(ShootGame.WIDTH - width);  \n        awardType = rand.nextInt(2);   //初始化时给奖励  \n    }  \n      \n    /** 获得奖励类型 */  \n    public int getType(){  \n        return awardType;  \n    }  \n  \n    /** 越界处理 */  \n    @Override  \n    public boolean outOfBounds() {  \n        return y>ShootGame.HEIGHT;  \n    }  \n  \n    /** 移动，可斜着飞 */  \n    @Override  \n    public void step() {        \n        x += xSpeed;  \n        y += ySpeed;  \n        if(x > ShootGame.WIDTH-width){    \n            xSpeed = -1;  \n        }  \n        if(x < 0){  \n            xSpeed = 1;  \n        }  \n    }  \n}\n```\n\n>子弹类：是飞行物体\n\n```\n/** \n * 子弹类:是飞行物 \n */  \npublic class Bullet extends FlyingObject {  \n    private int speed = 3;  //移动的速度  \n      \n    /** 初始化数据 */  \n    public Bullet(int x,int y){  \n        this.x = x;  \n        this.y = y;  \n        this.image = ShootGame.bullet;  \n    }  \n  \n    /** 移动 */  \n    @Override  \n    public void step(){     \n        y-=speed;  \n    }  \n  \n    /** 越界处理 */  \n    @Override  \n    public boolean outOfBounds() {  \n        return y<-height;  \n    }  \n  \n}  \n```\n\n>敌人的分数\n\n```\n/** \n * 敌人，可以有分数 \n */  \npublic interface Enemy {  \n    /** 敌人的分数  */  \n    int getScore();  \n}  \n```\n\n>飞行物(敌机，蜜蜂，子弹，英雄机)\n\n```\nimport java.awt.image.BufferedImage;  \n  \n/** \n * 飞行物(敌机，蜜蜂，子弹，英雄机) \n */  \npublic abstract class FlyingObject {  \n    protected int x;    //x坐标  \n    protected int y;    //y坐标  \n    protected int width;    //宽  \n    protected int height;   //高  \n    protected BufferedImage image;   //图片  \n  \n    public int getX() {  \n        return x;  \n    }  \n  \n    public void setX(int x) {  \n        this.x = x;  \n    }  \n  \n    public int getY() {  \n        return y;  \n    }  \n  \n    public void setY(int y) {  \n        this.y = y;  \n    }  \n  \n    public int getWidth() {  \n        return width;  \n    }  \n  \n    public void setWidth(int width) {  \n        this.width = width;  \n    }  \n  \n    public int getHeight() {  \n        return height;  \n    }  \n  \n    public void setHeight(int height) {  \n        this.height = height;  \n    }  \n  \n    public BufferedImage getImage() {  \n        return image;  \n    }  \n  \n    public void setImage(BufferedImage image) {  \n        this.image = image;  \n    }  \n  \n    /** \n     * 检查是否出界 \n     * @return true 出界与否 \n     */  \n    public abstract boolean outOfBounds();  \n      \n    /** \n     * 飞行物移动一步 \n     */  \n    public abstract void step();  \n      \n    /** \n     * 检查当前飞行物体是否被子弹(x,y)击(shoot)中 \n     * @param Bullet 子弹对象 \n     * @return true表示被击中了 \n     */  \n    public boolean shootBy(Bullet bullet){  \n        int x = bullet.x;  //子弹横坐标  \n        int y = bullet.y;  //子弹纵坐标  \n        return this.x<x && x<this.x+width && this.y<y && y<this.y+height;  \n    }  \n  \n}  \n```\n\n>英雄机\n\n```\nimport java.awt.image.BufferedImage;  \n  \n/** \n * 英雄机:是飞行物 \n */  \npublic class Hero extends FlyingObject{  \n      \n    private BufferedImage[] images = {};  //英雄机图片  \n    private int index = 0;                //英雄机图片切换索引  \n      \n    private int doubleFire;   //双倍火力  \n    private int life;   //命  \n      \n    /** 初始化数据 */  \n    public Hero(){  \n        life = 3;   //初始3条命  \n        doubleFire = 0;   //初始火力为0  \n        images = new BufferedImage[]{ShootGame.hero0, ShootGame.hero1}; //英雄机图片数组  \n        image = ShootGame.hero0;   //初始为hero0图片  \n        width = image.getWidth();  \n        height = image.getHeight();  \n        x = 150;  \n        y = 400;  \n    }  \n      \n    /** 获取双倍火力 */  \n    public int isDoubleFire() {  \n        return doubleFire;  \n    }  \n  \n    /** 设置双倍火力 */  \n    public void setDoubleFire(int doubleFire) {  \n        this.doubleFire = doubleFire;  \n    }  \n      \n    /** 增加火力 */  \n    public void addDoubleFire(){  \n        doubleFire = 40;  \n    }  \n      \n    /** 增命 */  \n    public void addLife(){  //增命  \n        life++;  \n    }  \n      \n    /** 减命 */  \n    public void subtractLife(){   //减命  \n        life--;  \n    }  \n      \n    /** 获取命 */  \n    public int getLife(){  \n        return life;  \n    }  \n      \n    /** 当前物体移动了一下，相对距离，x,y鼠标位置  */  \n    public void moveTo(int x,int y){     \n        this.x = x - width/2;  \n        this.y = y - height/2;  \n    }  \n  \n    /** 越界处理 */  \n    @Override  \n    public boolean outOfBounds() {  \n        return false;    \n    }  \n  \n    /** 发射子弹 */  \n    public Bullet[] shoot(){     \n        int xStep = width/4;      //4半  \n        int yStep = 20;  //步  \n        if(doubleFire>0){  //双倍火力  \n            Bullet[] bullets = new Bullet[2];  \n            bullets[0] = new Bullet(x+xStep,y-yStep);  //y-yStep(子弹距飞机的位置)  \n            bullets[1] = new Bullet(x+3*xStep,y-yStep);  \n            return bullets;  \n        }else{      //单倍火力  \n            Bullet[] bullets = new Bullet[1];  \n            bullets[0] = new Bullet(x+2*xStep,y-yStep);    \n            return bullets;  \n        }  \n    }  \n  \n    /** 移动 */  \n    @Override  \n    public void step() {  \n        if(images.length>0){  \n            image = images[index++/10%images.length];  //切换图片hero0，hero1  \n        }  \n    }  \n      \n    /** 碰撞算法 */  \n    public boolean hit(FlyingObject other){  \n          \n        int x1 = other.x - this.width/2;                 //x坐标最小距离  \n        int x2 = other.x + this.width/2 + other.width;   //x坐标最大距离  \n        int y1 = other.y - this.height/2;                //y坐标最小距离  \n        int y2 = other.y + this.height/2 + other.height; //y坐标最大距离  \n      \n        int herox = this.x + this.width/2;               //英雄机x坐标中心点距离  \n        int heroy = this.y + this.height/2;              //英雄机y坐标中心点距离  \n          \n        return herox>x1 && herox<x2 && heroy>y1 && heroy<y2;   //区间范围内为撞上了  \n    }  \n      \n}  \n```\n\n>游戏启动主类\n\n```\nimport java.awt.Font;  \nimport java.awt.Color;  \nimport java.awt.Graphics;  \nimport java.awt.event.MouseAdapter;  \nimport java.awt.event.MouseEvent;  \nimport java.util.Arrays;  \nimport java.util.Random;  \nimport java.util.Timer;  \nimport java.util.TimerTask;  \nimport java.awt.image.BufferedImage;  \n  \nimport javax.imageio.ImageIO;  \nimport javax.swing.ImageIcon;  \nimport javax.swing.JFrame;  \nimport javax.swing.JPanel;  \n  \npublic class ShootGame extends JPanel {  \n    public static final int WIDTH = 400; // 面板宽  \n    public static final int HEIGHT = 654; // 面板高  \n    /** 游戏的当前状态: START RUNNING PAUSE GAME_OVER */  \n    private int state;  \n    private static final int START = 0;  \n    private static final int RUNNING = 1;  \n    private static final int PAUSE = 2;  \n    private static final int GAME_OVER = 3;  \n  \n    private int score = 0; // 得分  \n    private Timer timer; // 定时器  \n    private int intervel = 1000 / 100; // 时间间隔(毫秒)  \n  \n    public static BufferedImage background;  \n    public static BufferedImage start;  \n    public static BufferedImage airplane;  \n    public static BufferedImage bee;  \n    public static BufferedImage bullet;  \n    public static BufferedImage hero0;  \n    public static BufferedImage hero1;  \n    public static BufferedImage pause;  \n    public static BufferedImage gameover;  \n  \n    private FlyingObject[] flyings = {}; // 敌机数组  \n    private Bullet[] bullets = {}; // 子弹数组  \n    private Hero hero = new Hero(); // 英雄机  \n  \n    static { // 静态代码块，初始化图片资源  \n        try {  \n            background = ImageIO.read(ShootGame.class  \n                    .getResource(\"background.png\"));  \n            start = ImageIO.read(ShootGame.class.getResource(\"start.png\"));  \n            airplane = ImageIO  \n                    .read(ShootGame.class.getResource(\"airplane.png\"));  \n            bee = ImageIO.read(ShootGame.class.getResource(\"bee.png\"));  \n            bullet = ImageIO.read(ShootGame.class.getResource(\"bullet.png\"));  \n            hero0 = ImageIO.read(ShootGame.class.getResource(\"hero0.png\"));  \n            hero1 = ImageIO.read(ShootGame.class.getResource(\"hero1.png\"));  \n            pause = ImageIO.read(ShootGame.class.getResource(\"pause.png\"));  \n            gameover = ImageIO  \n                    .read(ShootGame.class.getResource(\"gameover.png\"));  \n        } catch (Exception e) {  \n            e.printStackTrace();  \n        }  \n    }  \n  \n    /** 画 */  \n    @Override  \n    public void paint(Graphics g) {  \n        g.drawImage(background, 0, 0, null); // 画背景图  \n        paintHero(g); // 画英雄机  \n        paintBullets(g); // 画子弹  \n        paintFlyingObjects(g); // 画飞行物  \n        paintScore(g); // 画分数  \n        paintState(g); // 画游戏状态  \n    }  \n  \n    /** 画英雄机 */  \n    public void paintHero(Graphics g) {  \n        g.drawImage(hero.getImage(), hero.getX(), hero.getY(), null);  \n    }  \n  \n    /** 画子弹 */  \n    public void paintBullets(Graphics g) {  \n        for (int i = 0; i < bullets.length; i++) {  \n            Bullet b = bullets[i];  \n            g.drawImage(b.getImage(), b.getX() - b.getWidth() / 2, b.getY(),  \n                    null);  \n        }  \n    }  \n  \n    /** 画飞行物 */  \n    public void paintFlyingObjects(Graphics g) {  \n        for (int i = 0; i < flyings.length; i++) {  \n            FlyingObject f = flyings[i];  \n            g.drawImage(f.getImage(), f.getX(), f.getY(), null);  \n        }  \n    }  \n  \n    /** 画分数 */  \n    public void paintScore(Graphics g) {  \n        int x = 10; // x坐标  \n        int y = 25; // y坐标  \n        Font font = new Font(Font.SANS_SERIF, Font.BOLD, 22); // 字体  \n        g.setColor(new Color(0xFF0000));  \n        g.setFont(font); // 设置字体  \n        g.drawString(\"SCORE:\" + score, x, y); // 画分数  \n        y=y+20; // y坐标增20  \n        g.drawString(\"LIFE:\" + hero.getLife(), x, y); // 画命  \n    }  \n  \n    /** 画游戏状态 */  \n    public void paintState(Graphics g) {  \n        switch (state) {  \n        case START: // 启动状态  \n            g.drawImage(start, 0, 0, null);  \n            break;  \n        case PAUSE: // 暂停状态  \n            g.drawImage(pause, 0, 0, null);  \n            break;  \n        case GAME_OVER: // 游戏终止状态  \n            g.drawImage(gameover, 0, 0, null);  \n            break;  \n        }  \n    }  \n  \n    public static void main(String[] args) {  \n        JFrame frame = new JFrame(\"Fly\");  \n        ShootGame game = new ShootGame(); // 面板对象  \n        frame.add(game); // 将面板添加到JFrame中  \n        frame.setSize(WIDTH, HEIGHT); // 设置大小  \n        frame.setAlwaysOnTop(true); // 设置其总在最上  \n        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 默认关闭操作  \n        frame.setIconImage(new ImageIcon(\"images/icon.jpg\").getImage()); // 设置窗体的图标  \n        frame.setLocationRelativeTo(null); // 设置窗体初始位置  \n        frame.setVisible(true); // 尽快调用paint  \n  \n        game.action(); // 启动执行  \n    }  \n  \n    /** 启动执行代码 */  \n    public void action() {  \n        // 鼠标监听事件  \n        MouseAdapter l = new MouseAdapter() {  \n            @Override  \n            public void mouseMoved(MouseEvent e) { // 鼠标移动  \n                if (state == RUNNING) { // 运行状态下移动英雄机--随鼠标位置  \n                    int x = e.getX();  \n                    int y = e.getY();  \n                    hero.moveTo(x, y);  \n                }  \n            }  \n  \n            @Override  \n            public void mouseEntered(MouseEvent e) { // 鼠标进入  \n                if (state == PAUSE) { // 暂停状态下运行  \n                    state = RUNNING;  \n                }  \n            }  \n  \n            @Override  \n            public void mouseExited(MouseEvent e) { // 鼠标退出  \n                if (state == RUNNING) { // 游戏未结束，则设置其为暂停  \n                    state = PAUSE;  \n                }  \n            }  \n  \n            @Override  \n            public void mouseClicked(MouseEvent e) { // 鼠标点击  \n                switch (state) {  \n                case START:  \n                    state = RUNNING; // 启动状态下运行  \n                    break;  \n                case GAME_OVER: // 游戏结束，清理现场  \n                    flyings = new FlyingObject[0]; // 清空飞行物  \n                    bullets = new Bullet[0]; // 清空子弹  \n                    hero = new Hero(); // 重新创建英雄机  \n                    score = 0; // 清空成绩  \n                    state = START; // 状态设置为启动  \n                    break;  \n                }  \n            }  \n        };  \n        this.addMouseListener(l); // 处理鼠标点击操作  \n        this.addMouseMotionListener(l); // 处理鼠标滑动操作  \n  \n        timer = new Timer(); // 主流程控制  \n        timer.schedule(new TimerTask() {  \n            @Override  \n            public void run() {  \n                if (state == RUNNING) { // 运行状态  \n                    enterAction(); // 飞行物入场  \n                    stepAction(); // 走一步  \n                    shootAction(); // 英雄机射击  \n                    bangAction(); // 子弹打飞行物  \n                    outOfBoundsAction(); // 删除越界飞行物及子弹  \n                    checkGameOverAction(); // 检查游戏结束  \n                }  \n                repaint(); // 重绘，调用paint()方法  \n            }  \n  \n        }, intervel, intervel);  \n    }  \n  \n    int flyEnteredIndex = 0; // 飞行物入场计数  \n  \n    /** 飞行物入场 */  \n    public void enterAction() {  \n        flyEnteredIndex++;  \n        if (flyEnteredIndex % 40 == 0) { // 400毫秒生成一个飞行物--10*40  \n            FlyingObject obj = nextOne(); // 随机生成一个飞行物  \n            flyings = Arrays.copyOf(flyings, flyings.length + 1);  \n            flyings[flyings.length - 1] = obj;  \n        }  \n    }  \n  \n    /** 走一步 */  \n    public void stepAction() {  \n        for (int i = 0; i < flyings.length; i++) { // 飞行物走一步  \n            FlyingObject f = flyings[i];  \n            f.step();  \n        }  \n  \n        for (int i = 0; i < bullets.length; i++) { // 子弹走一步  \n            Bullet b = bullets[i];  \n            b.step();  \n        }  \n        hero.step(); // 英雄机走一步  \n    }  \n  \n    /** 飞行物走一步 */  \n    public void flyingStepAction() {  \n        for (int i = 0; i < flyings.length; i++) {  \n            FlyingObject f = flyings[i];  \n            f.step();  \n        }  \n    }  \n  \n    int shootIndex = 0; // 射击计数  \n  \n    /** 射击 */  \n    public void shootAction() {  \n        shootIndex++;  \n        if (shootIndex % 30 == 0) { // 300毫秒发一颗  \n            Bullet[] bs = hero.shoot(); // 英雄打出子弹  \n            bullets = Arrays.copyOf(bullets, bullets.length + bs.length); // 扩容  \n            System.arraycopy(bs, 0, bullets, bullets.length - bs.length,  \n                    bs.length); // 追加数组  \n        }  \n    }  \n  \n    /** 子弹与飞行物碰撞检测 */  \n    public void bangAction() {  \n        for (int i = 0; i < bullets.length; i++) { // 遍历所有子弹  \n            Bullet b = bullets[i];  \n            bang(b); // 子弹和飞行物之间的碰撞检查  \n        }  \n    }  \n  \n    /** 删除越界飞行物及子弹 */  \n    public void outOfBoundsAction() {  \n        int index = 0; // 索引  \n        FlyingObject[] flyingLives = new FlyingObject[flyings.length]; // 活着的飞行物  \n        for (int i = 0; i < flyings.length; i++) {  \n            FlyingObject f = flyings[i];  \n            if (!f.outOfBounds()) {  \n                flyingLives[index++] = f; // 不越界的留着  \n            }  \n        }  \n        flyings = Arrays.copyOf(flyingLives, index); // 将不越界的飞行物都留着  \n  \n        index = 0; // 索引重置为0  \n        Bullet[] bulletLives = new Bullet[bullets.length];  \n        for (int i = 0; i < bullets.length; i++) {  \n            Bullet b = bullets[i];  \n            if (!b.outOfBounds()) {  \n                bulletLives[index++] = b;  \n            }  \n        }  \n        bullets = Arrays.copyOf(bulletLives, index); // 将不越界的子弹留着  \n    }  \n  \n    /** 检查游戏结束 */  \n    public void checkGameOverAction() {  \n        if (isGameOver()==true) {  \n            state = GAME_OVER; // 改变状态  \n        }  \n    }  \n  \n    /** 检查游戏是否结束 */  \n    public boolean isGameOver() {  \n          \n        for (int i = 0; i < flyings.length; i++) {  \n            int index = -1;  \n            FlyingObject obj = flyings[i];  \n            if (hero.hit(obj)) { // 检查英雄机与飞行物是否碰撞  \n                hero.subtractLife(); // 减命  \n                hero.setDoubleFire(0); // 双倍火力解除  \n                index = i; // 记录碰上的飞行物索引  \n            }  \n            if (index != -1) {  \n                FlyingObject t = flyings[index];  \n                flyings[index] = flyings[flyings.length - 1];  \n                flyings[flyings.length - 1] = t; // 碰上的与最后一个飞行物交换  \n  \n                flyings = Arrays.copyOf(flyings, flyings.length - 1); // 删除碰上的飞行物  \n            }  \n        }  \n          \n        return hero.getLife() <= 0;  \n    }  \n  \n    /** 子弹和飞行物之间的碰撞检查 */  \n    public void bang(Bullet bullet) {  \n        int index = -1; // 击中的飞行物索引  \n        for (int i = 0; i < flyings.length; i++) {  \n            FlyingObject obj = flyings[i];  \n            if (obj.shootBy(bullet)) { // 判断是否击中  \n                index = i; // 记录被击中的飞行物的索引  \n                break;  \n            }  \n        }  \n        if (index != -1) { // 有击中的飞行物  \n            FlyingObject one = flyings[index]; // 记录被击中的飞行物  \n  \n            FlyingObject temp = flyings[index]; // 被击中的飞行物与最后一个飞行物交换  \n            flyings[index] = flyings[flyings.length - 1];  \n            flyings[flyings.length - 1] = temp;  \n  \n            flyings = Arrays.copyOf(flyings, flyings.length - 1); // 删除最后一个飞行物(即被击中的)  \n  \n            // 检查one的类型(敌人加分，奖励获取)  \n            if (one instanceof Enemy) { // 检查类型，是敌人，则加分  \n                Enemy e = (Enemy) one; // 强制类型转换  \n                score += e.getScore(); // 加分  \n            } else { // 若为奖励，设置奖励  \n                Award a = (Award) one;  \n                int type = a.getType(); // 获取奖励类型  \n                switch (type) {  \n                case Award.DOUBLE_FIRE:  \n                    hero.addDoubleFire(); // 设置双倍火力  \n                    break;  \n                case Award.LIFE:  \n                    hero.addLife(); // 设置加命  \n                    break;  \n                }  \n            }  \n        }  \n    }  \n  \n    /** \n     * 随机生成飞行物 \n     *  \n     * @return 飞行物对象 \n     */  \n    public static FlyingObject nextOne() {  \n        Random random = new Random();  \n        int type = random.nextInt(20); // [0,20)  \n        if (type < 4) {  \n            return new Bee();  \n        } else {  \n            return new Airplane();  \n        }  \n    }  \n  \n}  \n```\n\n#写在最后\n以上就是这个游戏我整理的完整代码，因为图片差不多9张，所以图片没上传，需要图片的友友请简信我，最后，我做了一张思维导图贴出来让大家更好的理解OOP面向对象编程的过程。\n\n![](http://wblearn.github.io/img/in-post/public/2556999-8217513e89c06a4a.webp)\n\n\n\n>ps：码字很累，友友们点个赞或者关注，谢谢，么么哒~~\n>资源已上传(包括图片)，下载地址请<a href=\"http://download.csdn.net/detail/wudalang_gd/9694422\">戳这里</a>\n\n------2016/12/25更新---------------\n\n上面的小飞机游戏下载地址失效了，最近开通了[我的github博客](https://wblearn.github.io/)，欢迎大家测试，同时方便以后托管一些项目及资源。下载地址：[Java打飞机小游戏（附完整源码）](https://github.com/wblearn/Small-plane-game)"
  },
  {
    "path": "src/com/tarena/fly/Airplane.java",
    "content": "package com.tarena.fly;\n\nimport java.util.Random;\n\n/**\n * зɻ: ǷҲǵ\n */\npublic class Airplane extends FlyingObject implements Enemy {\n\tprivate int speed = 3;  //ƶ\n\t\n\t/** ʼ */\n\tpublic Airplane(){\n\t\tthis.image = ShootGame.airplane;\n\t\twidth = image.getWidth();\n\t\theight = image.getHeight();\n\t\ty = -height;          \n\t\tRandom rand = new Random();\n\t\tx = rand.nextInt(ShootGame.WIDTH - width);\n\t}\n\t\n\t/** ȡ */\n\t@Override\n\tpublic int getScore() {  \n\t\treturn 5;\n\t}\n\n\t/** //Խ紦 */\n\t@Override\n\tpublic \tboolean outOfBounds() {   \n\t\treturn y>ShootGame.HEIGHT;\n\t}\n\n\t/** ƶ */\n\t@Override\n\tpublic void step() {   \n\t\ty += speed;\n\t}\n\n}\n\n"
  },
  {
    "path": "src/com/tarena/fly/Award.java",
    "content": "package com.tarena.fly;\n/**\n * \n */\npublic interface Award {\n\tint DOUBLE_FIRE = 0;  //˫\n\tint LIFE = 1;   //1\n\t/** ý(01) */\n\tint getType();\n}\n"
  },
  {
    "path": "src/com/tarena/fly/Bee.java",
    "content": "package com.tarena.fly;\n\nimport java.util.Random;\n\n/** ۷ */\npublic class Bee extends FlyingObject implements Award{\n\tprivate int xSpeed = 1;   //xƶٶ\n\tprivate int ySpeed = 2;   //yƶٶ\n\tprivate int awardType;    //\n\t\n\t/** ʼ */\n\tpublic Bee(){\n\t\tthis.image = ShootGame.bee;\n\t\twidth = image.getWidth();\n\t\theight = image.getHeight();\n\t\ty = -height;\n\t\tRandom rand = new Random();\n\t\tx = rand.nextInt(ShootGame.WIDTH - width);\n\t\tawardType = rand.nextInt(2);   //ʼʱ\n\t}\n\t\n\t/** ý */\n\tpublic int getType(){\n\t\treturn awardType;\n\t}\n\n\t/** Խ紦 */\n\t@Override\n\tpublic boolean outOfBounds() {\n\t\treturn y>ShootGame.HEIGHT;\n\t}\n\n\t/** ƶбŷ */\n\t@Override\n\tpublic void step() {      \n\t\tx += xSpeed;\n\t\ty += ySpeed;\n\t\tif(x > ShootGame.WIDTH-width){  \n\t\t\txSpeed = -1;\n\t\t}\n\t\tif(x < 0){\n\t\t\txSpeed = 1;\n\t\t}\n\t}\n}"
  },
  {
    "path": "src/com/tarena/fly/Bullet.java",
    "content": "package com.tarena.fly;\n\n/**\n * ӵ:Ƿ\n */\npublic class Bullet extends FlyingObject {\n\tprivate int speed = 3;  //ƶٶ\n\t\n\t/** ʼ */\n\tpublic Bullet(int x,int y){\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.image = ShootGame.bullet;\n\t}\n\n\t/** ƶ */\n\t@Override\n\tpublic void step(){   \n\t\ty-=speed;\n\t}\n\n\t/** Խ紦 */\n\t@Override\n\tpublic boolean outOfBounds() {\n\t\treturn y<-height;\n\t}\n\n}\n"
  },
  {
    "path": "src/com/tarena/fly/Enemy.java",
    "content": "package com.tarena.fly;\n\n/**\n * ˣз\n */\npublic interface Enemy {\n\t/** ˵ķ  */\n\tint getScore();\n}\n"
  },
  {
    "path": "src/com/tarena/fly/FlyingObject.java",
    "content": "package com.tarena.fly;\n\nimport java.awt.image.BufferedImage;\n\n/**\n * (л۷䣬ӵӢۻ)\n */\npublic abstract class FlyingObject {\n\tprotected int x;    //x\n\tprotected int y;    //y\n\tprotected int width;    //\n\tprotected int height;   //\n\tprotected BufferedImage image;   //ͼƬ\n\n\tpublic int getX() {\n\t\treturn x;\n\t}\n\n\tpublic void setX(int x) {\n\t\tthis.x = x;\n\t}\n\n\tpublic int getY() {\n\t\treturn y;\n\t}\n\n\tpublic void setY(int y) {\n\t\tthis.y = y;\n\t}\n\n\tpublic int getWidth() {\n\t\treturn width;\n\t}\n\n\tpublic void setWidth(int width) {\n\t\tthis.width = width;\n\t}\n\n\tpublic int getHeight() {\n\t\treturn height;\n\t}\n\n\tpublic void setHeight(int height) {\n\t\tthis.height = height;\n\t}\n\n\tpublic BufferedImage getImage() {\n\t\treturn image;\n\t}\n\n\tpublic void setImage(BufferedImage image) {\n\t\tthis.image = image;\n\t}\n\n\t/**\n\t * Ƿ\n\t * @return true \n\t */\n\tpublic abstract boolean outOfBounds();\n\t\n\t/**\n\t * ƶһ\n\t */\n\tpublic abstract void step();\n\t\n\t/**\n\t * 鵱ǰǷӵ(x,y)(shoot)\n\t * @param Bullet ӵ\n\t * @return trueʾ\n\t */\n\tpublic boolean shootBy(Bullet bullet){\n\t\tint x = bullet.x;  //ӵ\n\t\tint y = bullet.y;  //ӵ\n\t\treturn this.x<x && x<this.x+width && this.y<y && y<this.y+height;\n\t}\n\n}\n"
  },
  {
    "path": "src/com/tarena/fly/Hero.java",
    "content": "package com.tarena.fly;\nimport java.awt.image.BufferedImage;\n\n/**\n * Ӣۻ:Ƿ\n */\npublic class Hero extends FlyingObject{\n\t\n\tprivate BufferedImage[] images = {};  //ӢۻͼƬ\n\tprivate int index = 0;                //ӢۻͼƬл\n\t\n\tprivate int doubleFire;   //˫\n\tprivate int life;   //\n\t\n\t/** ʼ */\n\tpublic Hero(){\n\t\tlife = 3;   //ʼ3\n\t\tdoubleFire = 0;   //ʼΪ0\n\t\timages = new BufferedImage[]{ShootGame.hero0, ShootGame.hero1}; //ӢۻͼƬ\n\t\timage = ShootGame.hero0;   //ʼΪhero0ͼƬ\n\t\twidth = image.getWidth();\n\t\theight = image.getHeight();\n\t\tx = 150;\n\t\ty = 400;\n\t}\n\t\n\t/** ȡ˫ */\n\tpublic int isDoubleFire() {\n\t\treturn doubleFire;\n\t}\n\n\t/** ˫ */\n\tpublic void setDoubleFire(int doubleFire) {\n\t\tthis.doubleFire = doubleFire;\n\t}\n\t\n\t/** ӻ */\n\tpublic void addDoubleFire(){\n\t\tdoubleFire = 40;\n\t}\n\t\n\t/**  */\n\tpublic void addLife(){  //\n\t\tlife++;\n\t}\n\t\n\t/**  */\n\tpublic void subtractLife(){   //\n\t\tlife--;\n\t}\n\t\n\t/** ȡ */\n\tpublic int getLife(){\n\t\treturn life;\n\t}\n\t\n\t/** ǰƶһ£Ծ룬x,yλ  */\n\tpublic void moveTo(int x,int y){   \n\t\tthis.x = x - width/2;\n\t\tthis.y = y - height/2;\n\t}\n\n\t/** Խ紦 */\n\t@Override\n\tpublic boolean outOfBounds() {\n\t\treturn false;  \n\t}\n\n\t/** ӵ */\n\tpublic Bullet[] shoot(){   \n\t\tint xStep = width/4;      //4\n\t\tint yStep = 20;  //\n\t\tif(doubleFire>0){  //˫\n\t\t\tBullet[] bullets = new Bullet[2];\n\t\t\tbullets[0] = new Bullet(x+xStep,y-yStep);  //y-yStep(ӵɻλ)\n\t\t\tbullets[1] = new Bullet(x+3*xStep,y-yStep);\n\t\t\treturn bullets;\n\t\t}else{      //\n\t\t\tBullet[] bullets = new Bullet[1];\n\t\t\tbullets[0] = new Bullet(x+2*xStep,y-yStep);  \n\t\t\treturn bullets;\n\t\t}\n\t}\n\n\t/** ƶ */\n\t@Override\n\tpublic void step() {\n\t\tif(images.length>0){\n\t\t\timage = images[index++/10%images.length];  //лͼƬhero0hero1\n\t\t}\n\t}\n\t\n\t/** ײ㷨 */\n\tpublic boolean hit(FlyingObject other){\n\t\t\n\t\tint x1 = other.x - this.width/2;                 //xС\n\t\tint x2 = other.x + this.width/2 + other.width;   //x\n\t\tint y1 = other.y - this.height/2;                //yС\n\t\tint y2 = other.y + this.height/2 + other.height; //y\n\t\n\t\tint herox = this.x + this.width/2;               //Ӣۻxĵ\n\t\tint heroy = this.y + this.height/2;              //Ӣۻyĵ\n\t\t\n\t\treturn herox>x1 && herox<x2 && heroy>y1 && heroy<y2;   //䷶ΧΪײ\n\t}\n\t\n}\n\n\n\n\n\n\n\n\n\n\n"
  },
  {
    "path": "src/com/tarena/fly/ShootGame.java",
    "content": "package com.tarena.fly;\n\nimport java.awt.Font;\nimport java.awt.Color;\nimport java.awt.Graphics;\nimport java.awt.event.MouseAdapter;\nimport java.awt.event.MouseEvent;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Timer;\nimport java.util.TimerTask;\nimport java.awt.image.BufferedImage;\n\nimport javax.imageio.ImageIO;\nimport javax.swing.ImageIcon;\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\npublic class ShootGame extends JPanel {\n\tpublic static final int WIDTH = 400; // \n\tpublic static final int HEIGHT = 654; // \n\t/** Ϸĵǰ״̬: START RUNNING PAUSE GAME_OVER */\n\tprivate int state;\n\tprivate static final int START = 0;\n\tprivate static final int RUNNING = 1;\n\tprivate static final int PAUSE = 2;\n\tprivate static final int GAME_OVER = 3;\n\n\tprivate int score = 0; // ÷\n\tprivate Timer timer; // ʱ\n\tprivate int intervel = 1000 / 100; // ʱ()\n\n\tpublic static BufferedImage background;\n\tpublic static BufferedImage start;\n\tpublic static BufferedImage airplane;\n\tpublic static BufferedImage bee;\n\tpublic static BufferedImage bullet;\n\tpublic static BufferedImage hero0;\n\tpublic static BufferedImage hero1;\n\tpublic static BufferedImage pause;\n\tpublic static BufferedImage gameover;\n\n\tprivate FlyingObject[] flyings = {}; // л\n\tprivate Bullet[] bullets = {}; // ӵ\n\tprivate Hero hero = new Hero(); // Ӣۻ\n\n\tstatic { // ̬飬ʼͼƬԴ\n\t\ttry {\n\t\t\tbackground = ImageIO.read(ShootGame.class\n\t\t\t\t\t.getResource(\"background.png\"));\n\t\t\tstart = ImageIO.read(ShootGame.class.getResource(\"start.png\"));\n\t\t\tairplane = ImageIO\n\t\t\t\t\t.read(ShootGame.class.getResource(\"airplane.png\"));\n\t\t\tbee = ImageIO.read(ShootGame.class.getResource(\"bee.png\"));\n\t\t\tbullet = ImageIO.read(ShootGame.class.getResource(\"bullet.png\"));\n\t\t\thero0 = ImageIO.read(ShootGame.class.getResource(\"hero0.png\"));\n\t\t\thero1 = ImageIO.read(ShootGame.class.getResource(\"hero1.png\"));\n\t\t\tpause = ImageIO.read(ShootGame.class.getResource(\"pause.png\"));\n\t\t\tgameover = ImageIO\n\t\t\t\t\t.read(ShootGame.class.getResource(\"gameover.png\"));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\t/**  */\n\t@Override\n\tpublic void paint(Graphics g) {\n\t\tg.drawImage(background, 0, 0, null); // ͼ\n\t\tpaintHero(g); // Ӣۻ\n\t\tpaintBullets(g); // ӵ\n\t\tpaintFlyingObjects(g); // \n\t\tpaintScore(g); // \n\t\tpaintState(g); // Ϸ״̬\n\t}\n\n\t/** Ӣۻ */\n\tpublic void paintHero(Graphics g) {\n\t\tg.drawImage(hero.getImage(), hero.getX(), hero.getY(), null);\n\t}\n\n\t/** ӵ */\n\tpublic void paintBullets(Graphics g) {\n\t\tfor (int i = 0; i < bullets.length; i++) {\n\t\t\tBullet b = bullets[i];\n\t\t\tg.drawImage(b.getImage(), b.getX() - b.getWidth() / 2, b.getY(),\n\t\t\t\t\tnull);\n\t\t}\n\t}\n\n\t/**  */\n\tpublic void paintFlyingObjects(Graphics g) {\n\t\tfor (int i = 0; i < flyings.length; i++) {\n\t\t\tFlyingObject f = flyings[i];\n\t\t\tg.drawImage(f.getImage(), f.getX(), f.getY(), null);\n\t\t}\n\t}\n\n\t/**  */\n\tpublic void paintScore(Graphics g) {\n\t\tint x = 10; // x\n\t\tint y = 25; // y\n\t\tFont font = new Font(Font.SANS_SERIF, Font.BOLD, 22); // \n\t\tg.setColor(new Color(0xFF0000));\n\t\tg.setFont(font); // \n\t\tg.drawString(\"SCORE:\" + score, x, y); // \n\t\ty=y+20; // y20\n\t\tg.drawString(\"LIFE:\" + hero.getLife(), x, y); // \n\t}\n\n\t/** Ϸ״̬ */\n\tpublic void paintState(Graphics g) {\n\t\tswitch (state) {\n\t\tcase START: // ״̬\n\t\t\tg.drawImage(start, 0, 0, null);\n\t\t\tbreak;\n\t\tcase PAUSE: // ͣ״̬\n\t\t\tg.drawImage(pause, 0, 0, null);\n\t\t\tbreak;\n\t\tcase GAME_OVER: // Ϸֹ״̬\n\t\t\tg.drawImage(gameover, 0, 0, null);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tJFrame frame = new JFrame(\"Fly\");\n\t\tShootGame game = new ShootGame(); // \n\t\tframe.add(game); // ӵJFrame\n\t\tframe.setSize(WIDTH, HEIGHT); // ôС\n\t\tframe.setAlwaysOnTop(true); // \n\t\tframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // ĬϹرղ\n\t\tframe.setIconImage(new ImageIcon(\"images/icon.jpg\").getImage()); // ôͼ\n\t\tframe.setLocationRelativeTo(null); // ôʼλ\n\t\tframe.setVisible(true); // paint\n\n\t\tgame.action(); // ִ\n\t}\n\n\t/** ִд */\n\tpublic void action() {\n\t\t// ¼\n\t\tMouseAdapter l = new MouseAdapter() {\n\t\t\t@Override\n\t\t\tpublic void mouseMoved(MouseEvent e) { // ƶ\n\t\t\t\tif (state == RUNNING) { // ״̬ƶӢۻ--λ\n\t\t\t\t\tint x = e.getX();\n\t\t\t\t\tint y = e.getY();\n\t\t\t\t\thero.moveTo(x, y);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic void mouseEntered(MouseEvent e) { // \n\t\t\t\tif (state == PAUSE) { // ͣ״̬\n\t\t\t\t\tstate = RUNNING;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic void mouseExited(MouseEvent e) { // ˳\n\t\t\t\tif (state == RUNNING) { // ϷδΪͣ\n\t\t\t\t\tstate = PAUSE;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic void mouseClicked(MouseEvent e) { // \n\t\t\t\tswitch (state) {\n\t\t\t\tcase START:\n\t\t\t\t\tstate = RUNNING; // ״̬\n\t\t\t\t\tbreak;\n\t\t\t\tcase GAME_OVER: // Ϸֳ\n\t\t\t\t\tflyings = new FlyingObject[0]; // շ\n\t\t\t\t\tbullets = new Bullet[0]; // ӵ\n\t\t\t\t\thero = new Hero(); // ´Ӣۻ\n\t\t\t\t\tscore = 0; // ճɼ\n\t\t\t\t\tstate = START; // ״̬Ϊ\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tthis.addMouseListener(l); // \n\t\tthis.addMouseMotionListener(l); // 껬\n\n\t\ttimer = new Timer(); // ̿\n\t\ttimer.schedule(new TimerTask() {\n\t\t\t@Override\n\t\t\tpublic void run() {\n\t\t\t\tif (state == RUNNING) { // ״̬\n\t\t\t\t\tenterAction(); // 볡\n\t\t\t\t\tstepAction(); // һ\n\t\t\t\t\tshootAction(); // Ӣۻ\n\t\t\t\t\tbangAction(); // ӵ\n\t\t\t\t\toutOfBoundsAction(); // ɾԽＰӵ\n\t\t\t\t\tcheckGameOverAction(); // Ϸ\n\t\t\t\t}\n\t\t\t\trepaint(); // ػ棬paint()\n\t\t\t}\n\n\t\t}, intervel, intervel);\n\t}\n\n\tint flyEnteredIndex = 0; // 볡\n\n\t/** 볡 */\n\tpublic void enterAction() {\n\t\tflyEnteredIndex++;\n\t\tif (flyEnteredIndex % 40 == 0) { // 400һ--10*40\n\t\t\tFlyingObject obj = nextOne(); // һ\n\t\t\tflyings = Arrays.copyOf(flyings, flyings.length + 1);\n\t\t\tflyings[flyings.length - 1] = obj;\n\t\t}\n\t}\n\n\t/** һ */\n\tpublic void stepAction() {\n\t\tfor (int i = 0; i < flyings.length; i++) { // һ\n\t\t\tFlyingObject f = flyings[i];\n\t\t\tf.step();\n\t\t}\n\n\t\tfor (int i = 0; i < bullets.length; i++) { // ӵһ\n\t\t\tBullet b = bullets[i];\n\t\t\tb.step();\n\t\t}\n\t\thero.step(); // Ӣۻһ\n\t}\n\n\t/** һ */\n\tpublic void flyingStepAction() {\n\t\tfor (int i = 0; i < flyings.length; i++) {\n\t\t\tFlyingObject f = flyings[i];\n\t\t\tf.step();\n\t\t}\n\t}\n\n\tint shootIndex = 0; // \n\n\t/**  */\n\tpublic void shootAction() {\n\t\tshootIndex++;\n\t\tif (shootIndex % 30 == 0) { // 300뷢һ\n\t\t\tBullet[] bs = hero.shoot(); // Ӣ۴ӵ\n\t\t\tbullets = Arrays.copyOf(bullets, bullets.length + bs.length); // \n\t\t\tSystem.arraycopy(bs, 0, bullets, bullets.length - bs.length,\n\t\t\t\t\tbs.length); // ׷\n\t\t}\n\t}\n\n\t/** ӵײ */\n\tpublic void bangAction() {\n\t\tfor (int i = 0; i < bullets.length; i++) { // ӵ\n\t\t\tBullet b = bullets[i];\n\t\t\tbang(b); // ӵͷ֮ײ\n\t\t}\n\t}\n\n\t/** ɾԽＰӵ */\n\tpublic void outOfBoundsAction() {\n\t\tint index = 0; // \n\t\tFlyingObject[] flyingLives = new FlyingObject[flyings.length]; // ŵķ\n\t\tfor (int i = 0; i < flyings.length; i++) {\n\t\t\tFlyingObject f = flyings[i];\n\t\t\tif (!f.outOfBounds()) {\n\t\t\t\tflyingLives[index++] = f; // Խ\n\t\t\t}\n\t\t}\n\t\tflyings = Arrays.copyOf(flyingLives, index); // Խķﶼ\n\n\t\tindex = 0; // Ϊ0\n\t\tBullet[] bulletLives = new Bullet[bullets.length];\n\t\tfor (int i = 0; i < bullets.length; i++) {\n\t\t\tBullet b = bullets[i];\n\t\t\tif (!b.outOfBounds()) {\n\t\t\t\tbulletLives[index++] = b;\n\t\t\t}\n\t\t}\n\t\tbullets = Arrays.copyOf(bulletLives, index); // Խӵ\n\t}\n\n\t/** Ϸ */\n\tpublic void checkGameOverAction() {\n\t\tif (isGameOver()==true) {\n\t\t\tstate = GAME_OVER; // ı״̬\n\t\t}\n\t}\n\n\t/** ϷǷ */\n\tpublic boolean isGameOver() {\n\t\t\n\t\tfor (int i = 0; i < flyings.length; i++) {\n\t\t\tint index = -1;\n\t\t\tFlyingObject obj = flyings[i];\n\t\t\tif (hero.hit(obj)) { // ӢۻǷײ\n\t\t\t\thero.subtractLife(); // \n\t\t\t\thero.setDoubleFire(0); // ˫\n\t\t\t\tindex = i; // ¼ϵķ\n\t\t\t}\n\t\t\tif (index != -1) {\n\t\t\t\tFlyingObject t = flyings[index];\n\t\t\t\tflyings[index] = flyings[flyings.length - 1];\n\t\t\t\tflyings[flyings.length - 1] = t; // ϵһｻ\n\n\t\t\t\tflyings = Arrays.copyOf(flyings, flyings.length - 1); // ɾϵķ\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn hero.getLife() <= 0;\n\t}\n\n\t/** ӵͷ֮ײ */\n\tpublic void bang(Bullet bullet) {\n\t\tint index = -1; // еķ\n\t\tfor (int i = 0; i < flyings.length; i++) {\n\t\t\tFlyingObject obj = flyings[i];\n\t\t\tif (obj.shootBy(bullet)) { // жǷ\n\t\t\t\tindex = i; // ¼еķ\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (index != -1) { // леķ\n\t\t\tFlyingObject one = flyings[index]; // ¼еķ\n\n\t\t\tFlyingObject temp = flyings[index]; // еķһｻ\n\t\t\tflyings[index] = flyings[flyings.length - 1];\n\t\t\tflyings[flyings.length - 1] = temp;\n\n\t\t\tflyings = Arrays.copyOf(flyings, flyings.length - 1); // ɾһ(е)\n\n\t\t\t// one(˼ӷ֣ȡ)\n\t\t\tif (one instanceof Enemy) { // ͣǵˣӷ\n\t\t\t\tEnemy e = (Enemy) one; // ǿת\n\t\t\t\tscore += e.getScore(); // ӷ\n\t\t\t} else { // Ϊý\n\t\t\t\tAward a = (Award) one;\n\t\t\t\tint type = a.getType(); // ȡ\n\t\t\t\tswitch (type) {\n\t\t\t\tcase Award.DOUBLE_FIRE:\n\t\t\t\t\thero.addDoubleFire(); // ˫\n\t\t\t\t\tbreak;\n\t\t\t\tcase Award.LIFE:\n\t\t\t\t\thero.addLife(); // ü\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * ɷ\n\t * \n\t * @return \n\t */\n\tpublic static FlyingObject nextOne() {\n\t\tRandom random = new Random();\n\t\tint type = random.nextInt(20); // [0,20)\n\t\tif (type < 4) {\n\t\t\treturn new Bee();\n\t\t} else {\n\t\t\treturn new Airplane();\n\t\t}\n\t}\n\n}\n"
  }
]