• 周四. 4 月 23rd, 2026

物嫩软件资讯网

软件资讯来物嫩

飞机射击游戏 (Java基础)

admin@wunen

5 月 6, 2025



飞机射击游戏 (Java基础)



超类FlingObject

package pers.zhaxi.shootgame.shoot01;
import java.util.Random;
/*
 * 所有飞行物的超类
 * 英雄机 Hero
 * 小敌机 Airplan
 * 大敌机 BigAirplan
 * 超大敌机 SuperAirplan
 * 所有相同的行为方法写到超类里,设置为普通方法,如有子类有自己的特征重写
 * 所有不同的行为方法写到超类里,设置为抽象方法
 */
public class FlingObject {

	//所有派生类飞行物共有的属性
	protected int width ;   //宽度
	protected int height ;  //高度
	protected int x ;       //位置 x坐标
	protected int y ;       //位置 y坐标
	
	/*
	*构造方法 父类构造方法
	*供子类的小敌机 大敌机 超敌机使用
	*因为他们的 x y 的设置相同 都要从上面随机向下运动
	*/
	public FlingObject(int width , int height ){
		this.width = width ;
		this.height = height ;
		Random ran = new Random() ;
		x = ran.nextInt(480-width) ;
		y = -height ;
	}
	//供子类的天空 英雄机 使用  
	public FlingObject(int width , int height, int x ,int y ){
		this.width = width ;
		this.height = height ;
		this.x = x ;
		this.y = y ;
	}	
	//如何运动的方法 供子类重写
	public vo

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注