飞机大战实验报告

上传人:汽*** 文档编号:562245947 上传时间:2023-04-04 格式:DOCX 页数:11 大小:48.69KB
返回 下载 相关 举报
飞机大战实验报告_第1页
第1页 / 共11页
飞机大战实验报告_第2页
第2页 / 共11页
飞机大战实验报告_第3页
第3页 / 共11页
飞机大战实验报告_第4页
第4页 / 共11页
飞机大战实验报告_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《飞机大战实验报告》由会员分享,可在线阅读,更多相关《飞机大战实验报告(11页珍藏版)》请在金锄头文库上搜索。

1、飞机大战实验报告专业:网络工程 132 班学号:139074298:仁强计算机科学与技术学院二零一六年十二月一、软件运行所需要的软硬件环境本系统是以Windows系统为操作平台,用Java编程语言来实现本系统所需功能的。本机 器的配置如下:处理器:CORE i7主频:1.2Hz以上内存:4G以上硬盘:HHD50G编程语言:Java开发环境:windows7开发软件:Eclipse Mars二、游戏流程1. 用户打开游戏,进入开始菜单。2. 用户点击开始游戏按钮,进入游戏界面;3. 用户通过触屏方式控制玩家飞机上下左右移动,躲避与子弹相撞;4. 游戏失败后,显示本次游戏得分,用的秒数和水平;5.

2、 退出游戏1、准备代码 设置窗口 使用双缓冲使飞机不闪烁Con sta nt设置窗口大小package .ahut .准备代码;public class Constant public static final int GAME_WIDTH= 350; public static final int GAME_HEIGHT= 600; package .ahut .准备代码;import java.awt.Image;import java.awt.image.BufferedImage;import java.io.IOException;import .URL;public class G

3、ameUtil private GameUtil () public static Image getImage(String path) BufferedImage bi = null;try URL u = GameUtil.class.getClassLoader().getResource(path); bi = javax.imageio.ImageIO.read(u); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); return bi;package .ahut .准备代码;

4、import java.awt.Frame;import java.awt.Graphics;import java.awt.Image;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;public class MyFrame extends Frame public void lauchFrame() setSize(Constant.GAME_WIDTH, Constant.GAME_HEIGHT); setLocation(100, 100);setVisible(true);new PaintT

5、hread().start(); addWindowListener(new WindowAdapter() Overridepublic void windowClosing(WindowEvent e) System.exit(0););private Image offScreenImage = null; public void update(Graphics g) if (offScreenImage = null)offScreenImage = this.createImage(Constant.GAME_WIDTH, Constant.GAME_HEIGHT);Graphics

6、 gOff = offScreenImage.getGraphics();paint(gOff); g.drawImage(offScreenImage, 0, 0, null);class PaintThread extends Thread public void run() while (true) repaint();try Thread.sleep(40); catch (InterruptedException e) / TODO Auto-generated catch block e.printStackTrace(); 主代码飞机:package .ahut.plane;im

7、port java.awt.Graphics;import java.awt.event.KeyEvent;impo rt .ahut .准备代码.GameUtil;public class Plane extends GameObject private boolean left, up, right, down; private boolean live = true;public void draw(Graphics g) if (live) g.drawImage(img, (int)x, (int)y, null); move();public void addDirection(K

8、eyEvent e) switch (e.getKeyCode() case KeyEvent.VK_LEFT:/左left = true; break;case KeyEvent.VK_UP:/上up = true; break;case KeyEvent.VK_RIGHT:/右right = true; break;case KeyEvent.VK_DOWN:/下down = true; break;default: break;public void minusDirection(KeyEvent e) switch (e.getKeyCode() case KeyEvent.VK_LE

9、FT:/左left = false; break;case KeyEvent.VK_UP:/上up = false; break;case KeyEvent.VK_RIGHT:/右right = false; break;case KeyEvent.VK_DOWN:/下down = false; break;default: break;public void move() if (left) x -= speed;if (right) x += speed;if (up) y -= speed;if (down) y += speed;public Plane(String imgpath,

10、 double x, double y) this.img = GameUtil.getImage(imgpath); this.width = img.getWidth(null);this.height = img.getHeight(null);this.x = x;this.y = y;public Plane() public void setLive(boolean live) this.live = live;public boolean isLive() return live;子弹:package .ahut.plane;import java.awt.Color;impor

11、t java.awt.Graphics;import java.awt.Rectangle;import .ahut .准备代码.Con sta nt;public class Bullet extends GameObject double degree;public Bullet() degree = Math.random() * Math.PI * 2;x = Constant.GAME_WIDTH / 2;y = Constant.GAME_HEIGHT / 2; width = 10;height = 10;public Rectangle getRect() return new

12、 Rectangle(int)x, (int)y, width, height); public void draw(Graphics g) Color oldColor = g.getColor();g.setColor(Color.yellow);g.fillOval(int)x, (int)y, width, height);x += speed * Math.cos(degree); y += speed * Math.sin(degree);if (y Constant.GAME_HEIGHT - height | y 30) degree = -degree;if (x Const

13、ant.GAME_WIDTH - width) degree = Math.PI - degree;g.setColor(oldColor);游戏对象:package .ahut.plane;import java.awt.Image;import java.awt.Rectangle;public class GameObject Image img;double x,y;int speed=5;int width,height;public Rectangle getRect() return new Rectangle(int)x, (int)y, width, height);publ

14、ic GameObject(Image img, double x, double y, int speed, int width, int height) super();this.img = img;this.x = x;this.y = y;this.speed = speed;this.width = width;this.height = height;public GameObject() 主线程package .ahut.plane;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.Image;import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent;import java.util.ArrayList;import java.util.Date;impo rt .ahut .准备代码.GameUtil; import .ahut .准备代码 MyF rame;public class PlaneGameFrame extends MyFrame Image bg = GameUtil.getImage(image/p

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号