飞机大战(Java)

飞机大战游戏可以产生小的敌机、大的敌机、小蜜蜂,这三类都是随机概率出现的,游戏打开的时候,鼠标单击,游戏开始, 自动发射子弹,英雄机跟随鼠标移动,当鼠标移到窗口外时,游戏暂停,当鼠标又移回时,游戏继续,子弹打中敌机和小蜜 蜂,当生命降到0时,消失,敌机 撞击到英雄机, 英雄机生命值-1, 直到0时, 游戏结束, 小敌机: 分数+,大敌机: 分数+ 奖励(生命值加成, 火力加成),小蜜蜂: 奖励(生命值加成, 火力加成)。...
摘要由CSDN通过智能技术生成

飞机大战 游戏规则:游戏可以产生小的敌机、大的敌机、小蜜蜂,这三类都是随机概率出现的,游戏打开的时候,鼠标单击,游戏开始, 自动发射子弹,英雄机跟随鼠标移动,当鼠标移到窗口外时,游戏暂停,当鼠标又移回时,游戏继续,子弹打中敌机和小蜜 蜂,当生命降到0时,消失,敌机 撞击到英雄机, 英雄机生命值-1, 直到0时, 游戏结束, 小敌机: 分数+,大敌机: 分数+ 奖励(生命值加成, 火力加成),小蜜蜂: 奖励(生命值加成, 火力加成)。

源码地址:https://gitee.com/lxlxlxl233/fly-battle

package com.chinasofti.shoot;

import java.util.Random;

//敌机
public class Airplane  extends FlyingObject implements Enemy{
    private int speed=2;//走步

    /*构造方法*/
    public Airplane(){
        image=ShootGame.airplane;
        width=image.getWidth();
        height=image.getHeight();
        Random rand =new Random();
        x=rand.nextInt(ShootGame.WIDTH-this.width);
        y=-this.height;

    }
    @Override
    public int getScore() {
        return 5;
    }

    @Override
    public void step() {
        y+=speed;
    }

    @Override
    public boolean outOfBounds() {
        return this.y>ShootGame.HEIGHT;
    }


}

 

package com.chinasofti.shoot;
//奖励
public interface Award {
    public int LIFE=1;//命
    public int DOUBLE_FIRE=0;//火力值

    /*获取奖励 0:火力值,1:命*/
    public int getType();
}
package com.chinasofti.shoot;

import java.util.Random;

//小蜜蜂
public class Bee extends FlyingObject implements Award {
    private int xspeed=1;//x轴速度
    private int yspeed=2;//y轴速度
    private int awardType;

    public Bee() {
        image=ShootGame.bee;
        width=image.getWidth();
        height=image.getHeight();
        Random rand=new Random();
        x=rand.nextInt(ShootGame.WIDTH-this.width);
        y=-this.height;
        awardType= rand.nextInt(2);
    }

    @Override
    public int getType() {
        return awardType;
    }

    @Override
    public void step() {
        y+=yspeed;
        x+=xspeed;
        if(x>ShootGame.WIDTH-this.width){//最右边
            xspeed=-1;
        }
        if(x<0){//最左边
            xspeed=1;
        }
    }

    @Override
    public boolean outOfBounds() {
        return this.y>ShootGame.HEIGHT;
    }


}
package com.chinasofti.shoot;

import java.util.Random;

//子弹
public class Bullet extends FlyingObject{
    private int speed=3;

    public Bullet(int x,int y) {
        image=ShootGame.bullet;
        width=image.getWidth();
        height=image.getHeight();
        Random rand =new Random();
        this.x=x;//随着英雄机移动
        this.y=y;//随着英雄机移动
    }

    @Override
    public void step() {
        y-=speed;
    }

    @Override
    public boolean outOfBounds() {
        return this.y<-this.height;
    }

}
package com.chinasofti.shoot;
//敌人
public interface Enemy {
    /*得分*/
    public int getScore();
}
package com.chinasofti.shoot;

import java.awt.image.BufferedImage;

//飞行物
public abstract class FlyingObject {
    protected BufferedImage image;//图片
    protected int width;//长
    protected int height;//宽
    p
  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值