《基于Java雷电游戏项目报告毕业论文》由会员分享,可在线阅读,更多相关《基于Java雷电游戏项目报告毕业论文(21页珍藏版)》请在金锄头文库上搜索。
1、报告创建时间:Java 程序设计实验报告年级、专业、班级2011 级网络 1 班2011 级网络 1 班2011 级网络 1 班姓名实验题目 编程实现雷电游戏实验时间 2013.10.22-2013.11.6 实验地点 主教 0410实验成绩 实验性质 验证性 设计性 综合性教师评价:算法/实验过程正确; 源程序/实验内容提交 程序结构/实验步骤合理;实验结果正确; 语法、语义正确; 报告规范; 其他:评价教师签名:一、实验目的利用 Java GUI、Java Graphics 和多线程技术,编写实现飞行射击游戏雷电。二、实验项目内容1、根据项目任务书,形成完整的需求分析。2、根据需求,完成详
2、细的设计。3、基于 Java 编程实现。3、实验过程或算法(源程序)关键代码:Boss.javapackage cqu;public class Boss extends FlyingObjectpublic Boss(int x) super(x, 0, 250, 100, Resources.bossPNG);/ TODO Auto-generated constructor stubOverridepublic void move(long time) / TODO 自动生成的方法存根public Bullet fire()int x=(int) (Math.random()*350);
3、int y=100;Bullet b=new Bullet(x,y,true);return b;Bullet.javapackage cqu;public class Bullet extends FlyingObject public int xSpeed;public Bullet(int x, int y,boolean enemy) super(x, y, 10, 10, Resources.bulletPNG);this.enemy=enemy;xSpeed=0;private boolean enemy;public boolean isEnemy() return enemy;
4、Overridepublic void move(long time) if(time%40=0)if(enemy)y+=30;elsey-=30;x+=xSpeed;CBullet.javapackage cqu;public class CBullet extends FlyingObject public CBullet(int x) super(x, 0, 30, 30, Resources.addPNG);Overridepublic void move(long time) if(time%160=0)y+=Math.random()*4+10;/ x+=4-Math.random
5、()*6;Enemy.javapublic class Enemy extends FlyingObject public Enemy(int x, int y) super(x, y, 40, 40, Resources.enemyPNG);public Bullet fire()int x=this.x+12;int y=this.y+this.height;Bullet b=new Bullet(x,y,true);return b;Overridepublic void move(long time) if(time%160=0)y+=Math.random()*4+10;/ x+=4
6、-Math.random()*6;FlyObject.javapackage cqu;import java.awt.Graphics;import java.awt.image.BufferedImage;abstract public class FlyingObject protected int x;protected int y;protected int width;protected int height;private BufferedImage image;public FlyingObject(int x, int y, int width, int height, Buf
7、feredImage image) super();this.x = x;this.y = y;this.width = width;this.height = height;this.image = image;abstract public void move(long time);public void draw(Graphics g)g.drawImage(image, x, y, width, height, null);public int getWidth() return width;public void setWidth(int width) this.width = wi
8、dth;public int getHeight() return height;public void setHeight(int height) this.height = height;/*public boolean collision(FlyingObject other)return false;*/public int getX() return x;public void setX(int x) this.x = x;public int getY() return y;public void setY(int y) this.y = y;GameCanvas.javapack
9、age cqu;import java.awt.Graphics;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.util.ArrayList;import java.util.List;import javax.swing.JPanel;public class GameCanvas extends JPanel implements KeyListe
10、nerprivate boolean start1=false;private boolean start2=true;Thread animate;CBullet cbullet=new CBullet(int)(Math.random()*350);int cflag=0;int isdeath=1;int end=0;int sflag=0;int y=0;int count=0;boolean click=false;private List enemies=new ArrayList();private List ebullets=new ArrayList();private Li
11、st hbullets=new ArrayList();private List blast =new ArrayList();private Hero hero;private Boss boss;public GameCanvas()this.addKeyListener(this);hero=new Hero(200,500);boss=new Boss(int)(Math.random()*150);Enemy e=new Enemy(int)(Math.random()*350),0);enemies.add(e);animate=new Thread()/int isdeath=1
12、;int scale=1;/int cflag=0;public void run()long time=0;while(true)try if(isdeath=1)time=0;click=false;ebullets.clear();hbullets.clear();enemies.clear();else if(isdeath=2)time=0;click=true;ebullets.clear();hbullets.clear();enemies.clear();else /if(isdeath=0)EnemyMove(time);for(Bullet e:ebullets)e.mov
13、e(time);for(Bullet h:hbullets)h.move(time);if(scale=1)if(time%1000=0)for(Enemy e:enemies)Bullet b=e.fire();ebullets.add(b);else if(time%800=0)for(Enemy e:enemies)Bullet b=e.fire();ebullets.add(b);if(end=1)for(int i=0;i=600)y=0;time+=40;Thread.sleep(50); catch (InterruptedException e) e.printStackTra
14、ce();repaint();blast.clear();private void getaway()for(int i=0;i600)enemies.remove(i);for(int i=0;i600)ebullets.remove(i);for(int i=0;i600)cflag=0;private void keymove()if(hero.up)hero.moveUp(8);if(hero.down)hero.moveDown(8);if(hero.left)hero.moveLeft(8);if(hero.right)hero.moveRight(8);private void
15、collision() int esize=enemies.size();/int hsize=hbullets.size();for(int i=0;i=1)for(int j=0;jboss.getX()&hbullets.get(i).getX()0&hbullets.get(i).getY()=300)isdeath=2;/*for(int i=0;ihero.getX()if(hero.getX()+25ebullets.get(i).getX()if(ebullets.get(i).getY()hero.getY()if(hero.getY()+25ebullets.get(i).getY()if(sflag=0)isdeath=1;elsesflag=0;Blast a=new Blast() ;a.set(hero.getX(),hero.getY();blast.add(a);ebullets.remove(i);break;*/if(cbullet.getX()hero.getX()if(cbullet.getY()hero.getX()+25)if(cbullet.getY()=50000&time=150000)if(end=0)if(time%100000=0)cflag=1;cbullet=new CBullet