Java飞机大战【3】游戏基本类

这是飞机大战游戏的基础工具类代码及解释,其他的也在博客中

基本类有三类,统一放在包com.airbattle.gameobject下

用途
Aircraft 飞行器,游戏中所有的飞行物(英雄机和敌机)都继承该类
Bullet

子弹类,主要是子弹的构造和移动

HostilePlane 敌军飞机,继承了飞行器类

这些类也被写残了,因为我的水平太差,只对后面的一些继承有约束作用,其他意义不大

Aircraft类

package com.airbattle.gameobject;

import com.airbattle.gameinterface.FlyingObjectInterface;
import com.airbattle.gameproperty.Image;
import com.airbattle.gameproperty.Position;

/**
 * 
 * @author William
 * 所有飞行器的父类
 * 英雄机和敌机都继承这个类
 *
 */
public abstract class Aircraft implements FlyingObjectInterface{
	//飞行器的位置
	public Position pos = new Position(0,0);
	public Aircraft(Position pos) {
		this.pos = pos;
	}
	public Aircraft() {
	}
}





Bullet类

package com.airbattle.gameobject;

import com.airbattle.gameinterface.GameObjectInterface;
import com.airbattle.gameproperty.Image;
import com.airbattle.gameproperty.Position;

public class Bullet implements GameObjectInterface{
	int damage;    //子弹的伤害,没用
	public Position pos;    //子弹的位置
	static {
		//System.out.println("子弹的图像文件已经被加载");
	}
	public Bullet(int damage, Position pos) {
		if (damage <= 0)
			damage = 1;
		this.damage = damage;
		this.pos = pos;
		//System.out.println("子弹的伤害已设置");
	}
    //子弹移动函数
	public void moveStep(int dir) {
		this.pos.x += dir;
	}
	public void moveStep() {

	}
	
	
}

 

HostilePlane类

package com.airbattle.gameobject;

import com.airbattle.game.Property;
import com.airbattle.gameinterface.FlyingObjectInterface;
import com.airbattle.gameinterface.GameObjectInterface;
import com.airbattle.gameproperty.Image;
import com.airbattle.gameproperty.Position;
import com.airbattle.gameproperty.Rect;

public class HostilePlane extends Aircraft implements FlyingObjectInterface, GameObjectInterface{
	
	public HostilePlane(Position pos) {
		super(pos);
	}
	public Bullet fire() {
		return null;
	}
	//获取敌方飞机的矩形框
	public Rect getRect() {
		
		return new Rect(this.pos.x, this.pos.y, Property.ENEMY_IMAGE_HEIGHT, Property.ENEMY_IMAGE_WIDTH);
		
	}
	
	
	
	public void moveStep() {
		
	}
	
	public void onHit(int numHit) {
		
	}
}

 

你可能感兴趣的:(java飞机大战,java,Java,Java,Swing,Java飞机大战)