eclipse飞机大战小游戏

飞机大战

Airplane.java类

package myshoot

public class Airplane extends FlyingObject implements Enemy {

private int speed = 2; 


/* 
 *   构造方法 
 * 
 */
public Airplane(){
	image = ShootGame.airplane; 
	width = image.getWidth(); 
	height = image.getHeight();
	x = (int) (Math.random()*(ShootGame.WIDTH-this.width));
	//x=100;
	//y=100;
}

/* 重写getScore() */
public int getScore(){
	return 5;
}

/*
 * 重写step()
*/
public void step(){
	y+=speed;
}

/* 
 * 重写outOfBounds() 
*/
public boolean outOfBounds(){
	return this.y>=ShootGame.HEIGHT;
}

}

Award.java
package myshoot;

public interface Award {
public int DOUBLE_FIRE = 0;
public int LIFE = 1;

/* 
*0获取奖励类型 0为火力 1为命
 */
public int getType();

}

Bee.java
package myshoot;

import java.util.Random;

public class Bee extends FlyingObject implements Award {
private int xSpeed = 1;
private int ySpeed = 2;
private int awardType;

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

// x=100;
// y=200;
}

/* 重写getType() */
public int getType(){
	return awardType; 
}

/* 重写step() */
public void step(){
	x+=xSpeed; 
	y+=ySpeed; 
	if(x>=ShootGame.WIDTH-this.width){ 
		xSpeed = -1;
	}
	if(x<=0){ 
		xSpeed = 1;
	}
}

/* 重写outOfBounds() */
public boolean outOfBounds(){
	return this.y>=ShootGame.HEIGHT;
}

}

Bullet.java
package myshoot;

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

public Bullet(int x,int y){
	image = ShootGame.bullet;
	this.x = x; 
	this.y = y; 
}

/* 重写step() */
public void step(){
	y-=speed; 
}


/* 重写outOfBounds() */
public boolean outOfBounds(){
	return this.y<=-this.height; 
}

}

Enemy.java
package my加粗样式shoot;
/*
* 敌人 ,可以有分数
*
/
public interface Enemy {
/

* 敌人的分数
*/
public int getScore();
}

FlyingObject.java
package myshoot;

import java.awt.image.BufferedImage;

public abstract class FlyingObject {

protected int x;
protected int y; 
protected int
protected int height; 
protected BufferedImage im
  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值