码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA课程设计——飞机大战(团队)

时间:2021-01-29 12:07:13      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:单机   view   提交   anti   str   system   height   ict   介绍   

1.团队名称、团队成员介绍

黄力强(组长)

带带带带...带佬

陈汉煜(组员)

划水.gif

2.Gitee部分

项目git地址:https://gitee.com/alpha-beta2001/java-code/tree/master/PlaneWar
提交记录:https://gitee.com/alpha-beta2001/java-code/commits/master

3.项目功能架构图与主要功能流程图

游戏流程图:
技术图片

面向对象设计

包图:
技术图片
uml(关键类):
技术图片

4.项目运行截图

技术图片
技术图片
技术图片
技术图片

5.项目关键代码

鼠标监听:

package com.listener;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;

import com.view.BFrame;


public class FrameMouseListener implements MouseMotionListener{
	
	public BFrame bFrame;
	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
		//开始后鼠标操控
		if(this.bFrame.nPanel.isStart == true)
		{
			this.bFrame.nPanel.plane.x=e.getX()-this.bFrame.nPanel.plane.width/2-5;
			this.bFrame.nPanel.plane.y=e.getY()-this.bFrame.nPanel.plane.height/2-15;
		}
		
		//死亡后按钮按压反馈
		if(this.bFrame.nPanel.isDead == true)
		{
			if((e.getX()>67&&e.getX()<405&&e.getY()>500&&e.getY()<606))
			{
				this.bFrame.nPanel.dg.ispress = true;
			}
			else
			{
				this.bFrame.nPanel.dg.ispress = false;
			}
			
			
		}

		//System.out.println(e.getX()+" "+e.getY());

	}


}

界面绘制线程(每隔几毫秒绘制一次画面):

package com.thread;

import com.view.BPanel;

public class DrawableTread extends Thread{
		
	public BPanel bPanel;
	public DrawableTread(BPanel bPanel) 
	{
		this.bPanel = bPanel;
	}
	@Override
	public void run()
	{
		while(true)
		{
			this.bPanel.repaint();
			try {
				this.currentThread().sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}

界面设计(需要绘制什么,绘制间隔):

package com.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

import javax.swing.JPanel;

import com.model.Background;
import com.model.Bullet;
import com.model.DeadDialog;
import com.model.Enemy;
import com.model.Enemy01;
import com.model.Item;
import com.model.MenuImage;
import com.model.Plane;
import com.thread.DrawableTread;
import com.thread.MusicThread;

public class BPanel extends JPanel{
	
	public Image background;
	public Background back;
	public int i = 0;
	public int j = 0;
	public int time = 0;
	public int top = 0;
	public int flag = 1;
	public DrawableTread dwtread;
	
	public MenuImage menu;
	public DeadDialog dg;
	public Plane plane;
	
	public ArrayList<Bullet> bts = new ArrayList<Bullet>();
	public ArrayList<Enemy> ens = new ArrayList<Enemy>();
	public ArrayList<Item> its = new ArrayList<Item>();
	/**所有敌机类型*/
	public ArrayList<Class> ensType = new ArrayList<Class>();

	public Boolean isStart = false;
	public Boolean isDead = false;
	
	public Boolean hasBullet = false;
	public Boolean hasEnemy = false;

	public BPanel()
	{	
		this.dwtread = new DrawableTread(this);
		this.menu = new MenuImage(this);
		this.dg = new DeadDialog(this);
		this.plane = new Plane(this);
		this.back = new Background(this);
		this.dwtread.start();
	}
	
	@Override
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		//界面时间
		time++;
		if(time == 10000) 
		{
			time = 0;
		}
		//背景绘制
		back.chooseType();
		this.back.drawBack(g);
		
		//界面动画
		if(isStart==false)
		{
			this.menu.drawImage(g);
		}
		else if(isStart==true)
		{
			
			this.menu.drawImageBack(g);;
		}
		
		//绘制飞机
		this.plane.chooseType();
		this.plane.drawplane(g);
		
		
		//子弹绘制
		if(hasBullet == true)
		{
			if(time%100==0)
			{
				new MusicThread("Music/shoot.wav").start();
				if(this.plane.mode == 1)
				{
					Bullet bt = new Bullet(this);
					bt.width = 15;
					bt.height = 65;
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 2)
				{
					Bullet bt = new Bullet(this);
					bt.width = 15;
					bt.height = 65;
					bt.x = this.plane.x+this.plane.width/4-bt.width/2+5;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.width = 15;
					bt1.height = 65;
					bt1.x = this.plane.x+this.plane.width*3/4-bt.width/2-5;
					bt1.y = this.plane.y;	
					this.bts.add(bt1);
				}
				else if(this.plane.mode == 3)
				{
					Bullet bt = new Bullet(this);
					bt.width = 15;
					bt.height = 65;
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.x = this.plane.x+this.plane.width/4-bt.width/2+2;
					Bullet bt2 = new Bullet(this);
					bt2.x = this.plane.x+this.plane.width*3/4-bt.width/2-2;
					bt1.y =bt2.y = bt.y+20;
					bt1.width =bt2.width= 15;
					bt1.height = bt2.height = 65;
					this.bts.add(bt1);
					this.bts.add(bt2);
				}
				else if(this.plane.mode == 4)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 2;
					
					bt.width = 10;
					bt.height = 20;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 5)
				{
					Bullet bt = new Bullet(this);
					bt.choose = 2;
					
					bt.width = 10;
					bt.height = 20;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.x = bt.x-10;
					Bullet bt2 = new Bullet(this);
					bt1.choose = bt2.choose = 2;
					
					bt2.x = bt.x+10;
					
					bt1.y =bt2.y = bt.y+10;
					bt1.width =bt2.width= 10;
					bt1.height = bt2.height = 20;
					this.bts.add(bt1);
					this.bts.add(bt2);
				}
				else if(this.plane.mode == 6)
				{
					Bullet bt = new Bullet(this);
					bt.choose = 2;
					
					bt.width = 10;
					bt.height = 20;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.x = bt.x-10;
					Bullet bt2 = new Bullet(this);
					bt1.choose = bt2.choose = 2;
					
					bt2.x = bt.x+10;
					
					bt1.y =bt2.y = bt.y+10;
					bt1.width =bt2.width= 10;
					bt1.height = bt2.height = 20;
					this.bts.add(bt1);
					this.bts.add(bt2);
					
					Bullet bt3 = new Bullet(this);
					bt3.x = bt.x-20;
					Bullet bt4 = new Bullet(this);
					bt3.choose = bt4.choose = 2;
					bt4.x = bt.x+20;
					
					bt3.y =bt4.y = bt.y+20;
					bt3.width =bt4.width= 10;
					bt3.height = bt4.height = 20;
					this.bts.add(bt3);
					this.bts.add(bt4);
				}
				else if(this.plane.mode == 7)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 3;
					
					bt.width = 10;
					bt.height = 45;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 8)
				{
					Bullet bt = new Bullet(this);
					bt.choose = 3;
					
					bt.width = 11;
					bt.height = 65;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
				}
				else if(this.plane.mode == 9)
				{
					Bullet bt = new Bullet(this);
					bt.choose = 3;
					
					bt.width = 11;
					bt.height = 100;
					
					bt.x = this.plane.x+this.plane.width/4;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.choose = 3;
					
					bt1.width = 11;
					bt1.height = 100;
					
					bt1.x = this.plane.x+this.plane.width*3/4-bt1.width;
					bt1.y = this.plane.y;
					this.bts.add(bt1);
				}
				else if(this.plane.mode == 10)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 4;
					
					bt.width = 17;
					bt.height = 22;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 11)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 4;
					
					bt.width = 25;
					bt.height = 32;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 12)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 4;
					
					bt.width = 32;
					bt.height = 40;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.choose = 4;
					
					bt1.width = 17;
					bt1.height = 22;
					
					bt1.x = this.plane.x+this.plane.width/2-bt1.width/2;
					bt1.y = this.plane.y+20;
					this.bts.add(bt1);
				}
				else if(this.plane.mode == 13)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 5;
					
					bt.width = 16;
					bt.height = 99;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 14)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 6;
					
					bt.width = 20;
					bt.height = 99;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 15)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 6;
					
					bt.width = 20;
					bt.height = 99;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.choose = 5;
					
					bt1.width = 10;
					bt1.height = 99;
					
					bt1.x = this.plane.x+this.plane.width/2-bt.width/2-10;
					bt1.y = this.plane.y+10;
					this.bts.add(bt1);
					
					Bullet bt2 = new Bullet(this);
					bt2.choose = 5;
					
					bt2.width = 10;
					bt2.height = 99;
					
					bt2.x = this.plane.x+this.plane.width/2-bt.width/2+20;
					bt2.y = this.plane.y+10;
					this.bts.add(bt2);
					
				}
				else if(this.plane.mode == 16)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 7;
					
					bt.width = 50;
					bt.height = 50;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
				}
				else if(this.plane.mode == 17)
				{
					
					Bullet bt = new Bullet(this);
					bt.choose = 7;
					
					bt.width = 50;
					bt.height = 50;
					
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.choose = 7;
					
					bt1.width = 30;
					bt1.height = 30;
					
					bt1.x = this.plane.x-30;
					bt1.y = this.plane.y+20;
					this.bts.add(bt1);
					
					Bullet bt2 = new Bullet(this);
					bt2.choose = 7;
					
					bt2.width = 30;
					bt2.height = 30;
					
					bt2.x = this.plane.x+this.plane.width;
					bt2.y = this.plane.y+20;
					this.bts.add(bt2);
					
					Bullet bt3 = new Bullet(this);
					Bullet bt4 = new Bullet(this);
					bt3.choose = bt4.choose = 2;
					bt3.x = this.plane.x;
					bt4.x = this.plane.x+this.plane.width-10;
					
					bt3.y =bt4.y = bt.y+10;
					bt3.width =bt4.width= 10;
					bt3.height = bt4.height = 20;
					this.bts.add(bt3);
					this.bts.add(bt4);
				}
				else if(this.plane.mode == 18)
				{
					Bullet bt = new Bullet(this);
					bt.choose = 1;
					bt.width = 15;
					bt.height = 65;
					bt.x = this.plane.x+this.plane.width/2-bt.width/2;
					bt.y = this.plane.y;
					this.bts.add(bt);
					
					Bullet bt1 = new Bullet(this);
					bt1.x = this.plane.x+this.plane.width/4-bt.width/2+2;
					Bullet bt2 = new Bullet(this);
					bt2.x = this.plane.x+this.plane.width*3/4-bt.width/2-2;
					bt2.choose = bt1.choose = 1;
					bt1.y =bt2.y = bt.y+20;
					bt1.width =bt2.width= 15;
					bt1.height = bt2.height = 65;
					this.bts.add(bt1);
					this.bts.add(bt2);
					
					Bullet bt3 = new Bullet(this);
					bt3.x = this.plane.x+this.plane.width/4-bt.width/2-10;
					Bullet bt4 = new Bullet(this);
					bt4.x = this.plane.x+this.plane.width*3/4-bt.width/2+10;
					bt3.choose = bt4.choose = 1;
					bt3.y =bt4.y = bt.y+40;
					bt3.width =bt4.width= 15;
					bt3.height = bt4.height = 65;
					this.bts.add(bt3);
					this.bts.add(bt4);
				}
			}
			for(j = 0;j<this.bts.size();j++)
			{
				this.bts.get(j).drawBullet(g);
			}
		}
		
		//创建敌机
		if(hasEnemy == true)
		{
			if(time%500==0)
			{
				if(this.ensType.size()>0)
				{
					int i = (int)(Math.random()*this.ensType.size());
					Enemy enemy = null;
						try {
							//反射创建
							enemy = (Enemy)this.ensType.get(i).getConstructors()[0].newInstance(new Object[] {this});
						} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
								| InvocationTargetException | SecurityException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					this.ens.add(enemy);
				}
			}
			for(i = 0;i<this.ens.size();i++)
			{
				this.ens.get(i).drawEnemy(g);
			}
		}
		
		//绘制道具
		if(isStart == true)
		{
			for(i = 0;i<this.its.size();i++)
			{
				this.its.get(i).drawItem(g);
			}
		}
		if(isStart == true)
		{
			g.setColor(Color.WHITE);
			g.setFont(new Font(" ",Font.BOLD, 20));
			g.drawString("SCORE "+this.plane.count+" ",BFrame.pageWidth-150,30);
			g.drawString("HP "+this.plane.hp+" ",50,30);
		}
		
		if(isDead == true)
		{
			this.dg.drawDialog(g);
		}
	}

}

6.代码扫描结果

技术图片
时间紧迫没有细致完成

改进及感想

1.飞机在顶上的时候容易触发伪死亡bug
2.子弹没有做到按照每一个机型分配一个相应的子弹
3.还有多种飞机路径没有实现
4.单机游戏,未使用数据库,未能实现多人功能
5.背景循环音乐没有实现

JAVA课程设计——飞机大战(团队)

标签:单机   view   提交   anti   str   system   height   ict   介绍   

原文地址:https://www.cnblogs.com/2b-or-not-2b-/p/14342149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!