Actual project --- Aircraft War (1) --- detailed explanation for beginners to learn and use

Object-oriented project combat---aircraft war day01---beginners are easy to use

demand analysis

insert image description here
insert image description here

Run the project effect and analyze it.

  • There are three types of enemies: small enemy planes, big enemy planes, and little bees.
    Hero planes can fire bullets, and bullets can hit enemies
  • The bullet destroys the small enemy aircraft----------The player gets 1 point
    The bullet destroys the big enemy aircraft----------The player gets 3 molecular
    bombs to destroy the little bee----- -----Hero machine rewards (1 life, 40 firepower)
  • If the firepower value of the hero machine is 0, it is single firepower (one bullet). If the
    firepower value of the hero machine is greater than 0, it is double firepower (two bullets). When
    firing double firepower once, the firepower value will be reduced by 2.
  • The enemy can collide with the hero machine. After the collision:
    the hero machine loses life, and at the same time, the hero machine clears the firepower.
    When the hero machine’s life is 0, the game is over

day01

Design object class:
1. Find objects: hero plane, bullet, small enemy plane, big enemy plane, little bee, sky
2. Extraction classes: Hero, Bullet, Airplane, BigAirplane, Bee, Sky
3. Member variables in the design class and method:
4. Create an object and test:

Create package:
cn.tedu.shoot
Create class:
Hero
Airplane
BigAirplane
Bullet
Bee
Sky
World

Code:

Airplane class:

package cn.tedu.shoot;

//小敌机类
public class Airplane {
    
    

	//小敌机的属性
	int width;//宽
	int height;//高
	int x;//x轴
	int y;//y轴
	int step;//速度
	//构造方法
	public Airplane() {
    
    
	}
	//有参构造
	public Airplane(int width,
		int height,int x,int y,int step) {
    
    
		//为属性赋值
		this.width=width;
		this.height=height;
		this.x=x;
		this.y=y;
		this.step=step;
	}
	//编写一个输出小敌机信息的方法show
	public void show() {
    
    
		System.out.println("宽:"+width+",高:"+height);
		System.out.println("x:"+x+",y:"+y);
		System.out.println("速度:"+step);
	}
	
}




Bee class:

package cn.tedu.shoot;

public class Bee {
    
    

	int width;
	int height;
	int x;
	int y;
	int xStep;//横向移动速度
	int yStep;//纵向移动速度

	public Bee() {
    
    
	}
	public Bee(int width,int height,
			int x,int y,int xStep,int yStep) {
    
    
		this.width=width;
		this.height=height;
		this.x=x;
		this.y=y;
		this.xStep=xStep;
		this.yStep=yStep;
	}

	public void show() {
    
    
		System.out.println("宽:"+width+
				",高:"+height);
		System.out.println("x:"+x+",y:"+y);
		System.out.println("x速度:"+xStep+
				",y速度"+yStep);
	}


}

BigAirplane class:

package cn.tedu.shoot;

public class BigAirplane {
    
    

	int width;
	int height;
	int x;
	int y;
	int step;
	
    public BigAirplane() {
    
    
    }	
    public BigAirplane(int width,int height,
    		int x,int y,int step) {
    
    
    	this.width=width;
    	this.height=height;
    	this.x=x;
    	this.y=y;
    	this.step=step;
    }
    
    public void show() {
    
    
    	System.out.println("宽:"+width+
    			",高:"+height);
    	System.out.println("x:"+x+",y:"+y);
    	System.out.println("速度:"+step);
    }
	
}

Bullet class:

package cn.tedu.shoot;

public class Bullet {
    
    
	
	int width;
	int height;
	int x;
	int y;
	int step;
	public Bullet() {
    
    
	}
	public Bullet(int width,int height,
			int x,int y,int step) {
    
    
		this.width=width;
		this.height=height;
		this.x=x;
		this.y=y;
		this.step=step;
	}
	
	public void show() {
    
    
		System.out.println("宽:"+width
				+",高:"+height);
		System.out.println("x:"+x+",y:"+y);
		System.out.println("速度:"+step);
	}
		
	
	
}

Hero class:

package cn.tedu.shoot;

public class Hero {
    
    
	
	int width;
	int height;
	int x;
	int y;
	int life;//生命值
	int doubleFire;//火力值
	
	public Hero() {
    
    
	}
	public Hero(int width,int height,int x,
			int y,int life,int doubleFire) {
    
    
		this.width=width;
		this.height=height;
		this.x=x;
		this.y=y;
		this.life=life;
		this.doubleFire=doubleFire;
	}
	
	public void show() {
    
    
		System.out.println("宽:"+width
				+",高:"+height);
		System.out.println("x:"+x+",y:"+y);
		System.out.println("生命值:"+life);
		System.out.println("火力值:"+doubleFire);
		
	}
	
}

Sky class:

package cn.tedu.shoot;

public class Sky {
    
    

	int width;
	int height;
	int x;
	int y;
	int step;
	int y1;//第二张背景图的y轴坐标
	public Sky() {
    
    
	}
	public Sky(int width,int height,
			int x,int y,int step,int y1) {
    
    
		this.width=width;
		this.height=height;
		this.x=x;
		this.y=y;
		this.step=step;
		this.y1=y1;
	}
	public void show() {
    
    
		System.out.println("宽:"+width
				+",高"+height);
		System.out.println("x:"+x+",y:"
				+y+",y1:"+y1);
		System.out.println("速度:"+step);
	}
	
	
}

World class:

package cn.tedu.shoot;

public class World {
    
    

	public static void main(String[] args) {
    
    
		Airplane a1=new Airplane(50,40,220,400,4);
		a1.show();
		
	}

}

*Follow up and continue to learn, if it is useful, please like it, pay attention to it, and welcome blog comments~~~~! ! ! *

Guess you like

Origin blog.csdn.net/weixin_43639180/article/details/117370354