飞机大战编程过程 java飞机大战小游戏( 五 )


}
@Override
public Rectangle getRect() {
return null;
}
}
*//**
* 创造一个连接画出枪弹的线程
*//*
class CreateBullet extends Thread{
@Override
public void run() {
while(true){
try {
Bullet bullet=new Bullet();
bullet.x=x+32;
bullet.y=y+20;
arrayList.add(bullet);
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}*/
}
2.4战机连接展示类
package com.eneity;
import com.view.GamePanel;
import java.util.Random;
/**
* 源源不绝的创造敌机
*/
public class CreateEnemy extends Thread{
Random random =new Random();//创造随机数保护历次展示的敌机x坐标随机展示
@Override
public void run() {
while(true){
try {
EnemyPlane e= new EnemyPlane();
e.x=random.nextInt(650)+50;
e.y=-150;
GamePanel.EnemyPlaneArrayList.add(e);
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
3.controller遏制铁鸟挪动层
3.1PlaneController类
package com.controller;
import com.eneity.FightPlane;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/**
* 遏制铁鸟疏通
*/
public class PlaneController extends KeyAdapter {
FightPlane fightPlane;
public PlaneController(FightPlane fightPlane){
this.fightPlane=fightPlane;
}
@Override
public void keyPressed(KeyEvent e) {
diretion(e.getKeyCode());
}
//遏制铁鸟挪动
public void diretion(int code){
switch(code){
case 37://对应键盘左键
fightPlane.x-=15;
break;
case 38://对应键盘上键
fightPlane.y-=15;
break;
case 39://对应键盘右键
fightPlane.x+=15;
break;
case 40://对应键盘下键
fightPlane.y+=5;
break;
}
}
}
4.utils东西层
4.1铁鸟恒量类
package com.utils;
/**
* 用来设置运用到的恒量类
*/
public class P {
public static int HEIGHT=800,WEIGHT=800;
}
4.2加载图片类
package com.utils;
import javax.swing.*;
import java.awt.*;
import java.util.Objects;
/**
* 加载图片东西?

推荐阅读