飞机大战
实现代码
飞行物原型
package PlaneFight;
import java.awt.image.BufferedImage;
public abstract class prototype {
private int x,y,hp,height,weight,score;
protected BufferedImage image;
protected BufferedImage[] explosion;
public BufferedImage[] getExplosion() {
return explosion;
}
public void setExplosion(BufferedImage[] explosion) {
this.explosion = explosion;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public BufferedImage getImg() {
return img;
}
public void setImg(BufferedImage img) {
this.img = img;
}
private BufferedImage img;
public prototype() {
this.x = x;
this.y = y;
this.hp = hp;
this.height = height;
this.weight = weight;
this.img = img;
}
public abstract void move();
public boolean hitBy(Bullets bullet) {
int x = bullet.getX();
int y = bullet.getY();
return x>this.x && x<this.x+this.weight && y>this.y && y<this.y+this.height;
}
}
小敌机
package PlaneFight;
import java.awt.image.BufferedImage;
public class Small extends prototype{
private int speed,score;
BufferedImage[] imgss={
JPanelDemo.small2,JPanelDemo.small3,JPanelDemo.small4,JPanelDemo.small5};
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public Small(){
this.setX((int)(Math.random()*(Test.WIN_WIDTH-JPanelDemo.big.getWidth())));
this.setY(0-JPanelDemo.small.getHeight());
this.setHeight(JPanelDemo.small.getHeight());
this.setWeight(JPanelDemo.small.getWidth());
this.setHp(3);
this.setSpeed(4);
this.setScore(1);
this.setImg(JPanelDemo.small);
this.setExplosion(JPanelDemo.airplaneEmber);
}
public void move(){
this.setY(this.getY()+this.getSpeed());
}
}
大敌机
package PlaneFight;
public class Big extends prototype{
private int speed,score;
public Big(){
this.setX((int)(Math.random()*(Test.WIN_WIDTH-JPanelDemo.big.getWidth())));
this.setY(0-JPanelDemo.big.getHeight());
this.setHeight(JPanelDemo.big.getHeight());
this.setWeight(JPanelDemo.big.getWidth());
this.setHp(10);
this.setSpeed(3);
this.setScore(5);
this.setImg(JPanelDemo.big);
this.setExplosion(JPanelDemo.bigPlaneEmber);
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public void move(){
this.setY(this.getY()+this.getSpeed());
}
}
小蜜蜂
package PlaneFight;
public class Bee extends prototype{
private int speed,score;
public Bee(){
this.setX((int)(Math.random()*(Test.WIN_WIDTH-JPanelDemo.big.getWidth())));
this.setY(0-JPanelDemo.bee.getHeight());
this.setHeight(JPanelDemo.bee.getHeight());
this.setWeight(JPanelDemo.bee.getWidth());
this.setHp(