飞机大战
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