package cn.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;
import cn.sunSystem.Constant;
import cn.sunSystem.GameUtil;
import cn.sunSystem.MyFrame;
public class PlaneGame extends MyFrame {
Image bg=GameUtil.getImage("images3/bk.jpg");
Plane p=new Plane("images3/plane.png",50,50);
ArrayList bulletList=new ArrayList();
Explode bao;
Date startTime;
Date endTime;
Date nowTime;
public void paint(Graphics g){
g.drawImage(bg, 0, 0, null);
p.draw(g);
for(int i=0;i<bulletList.size();i++){
Bullet b=(Bullet) bulletList.get(i);
b.draw(g);
//检测碰撞
//基于矩形的检测
boolean peng=p.getRect().intersects(b.getRect());
if(peng){
System.out.println("###碰###");
p.setLive(false);//飞机死掉
if(bao==null){
endTime=new Date();
bao=new Explode(p.x,p.y);
}
bao.draw(g);
break;
}
}
if(p.isLive()){
nowTime=new Date();
int period1 =(int)(nowTime.getTime()-startTime.getTime())/1000;
printInfor(g,"时间:"+period1+"秒",20,Color.yellow,300,80);
}
if(!p.isLive()){
printInfor(g,"GAME OVER",50,Color.red,Constant.GAME_WIDTH/2-100,Constant.GAME_HEIGHT/2);
int period =(int)(endTime.getTime()-startTime.getTime())/1000;
printInfor(g,"时间:"+period+"秒",30,Color.yellow,Constant.GAME_WIDTH/2-100,Constant.GAME_HEIGHT/2+100);
switch (period/10) {
case 0:
case 1:
printInfor(g,"菜鸟",20,Color.yellow,Constant.GAME_WIDTH/2-100,Constant.GAME_HEIGHT/2+200);
break;
case 2:
printInfor(g,"不错",20,Color.yellow,Constant.GAME_WIDTH/2-100,Constant.GAME_HEIGHT/2+200);
break;
case 3:
printInfor(g,"很棒",20,Color.yellow,Constant.GAME_WIDTH/2-100,Constant.GAME_HEIGHT/2+200);
break;
case 4:
printInfor(g,"大师",20,Color.yellow,Constant.GAME_WIDTH/2-100,Constant.GAME_HEIGHT/2+200);
break;
default:
printInfor(g,"世界已无法阻止你的脚步",20,Color.yellow,Constant.GAME_WIDTH/2-100,Constant.GAME_HEIGHT/2+200);
break;
}
}
}
/**
* 在窗口打印信息
*/
public void printInfor(Graphics g,String str,int size,Color color,int x,int y){
Color c=g.getColor();
g.setColor(color);
Font f=new Font("宋体",Font.BOLD,size);
g.setFont(f);
g.drawString(str, x,y);
g.setColor(c);
}
public static void main(String[] args) {
new PlaneGame().lanchFrame();
}
@Override
public void lanchFrame() {
super.lanchFrame();
//增加键盘监听
addKeyListener(new KeyMonitor());
//生成一堆子弹
for(int i=0;i<10;i++){
Bullet b=new Bullet();
bulletList.add(b);
}
startTime=new Date();
}
//定义为内部类,可以方便的使用外部类的普通属性
class KeyMonitor extends KeyAdapter{
@Override
public void keyPressed(KeyEvent e) {
System.out.println("按下"+e.getKeyCode());
p.Direction(e);
}
@Override
public void keyReleased(KeyEvent e) {
System.out.println("弹起"+e.getKeyCode());
p.Undirection(e);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java小游戏开发代码
共198个文件
jpg:48个
gif:32个
class:30个
需积分: 41 11 下载量 127 浏览量
2017-10-07
15:21:31
上传
评论
收藏 4.9MB RAR 举报
温馨提示
java窗口小游戏开发,可作为java初级入门者学习使用。直接运行src\cn\zlr\game包下的MyFrame这个类可看到其中一个小游戏的运行。其他小游戏可能存在不完整的情况,读者可自行拓展
资源推荐
资源详情
资源评论
收起资源包目录
java小游戏开发代码 (198个子文件)
PlaneGame.class 4KB
IFrame3.class 2KB
Plant.class 2KB
Plane.class 2KB
Sun.class 2KB
IFrame.class 2KB
IFrame4.class 2KB
IFrame4.class 2KB
IFrame2.class 2KB
Explode.class 1KB
Start.class 1KB
MyFrame.class 1KB
PlaneGame$KeyMonitor.class 1KB
Bullet.class 1KB
GameUtil.class 1010B
GameUtil.class 1008B
PlaneObject.class 843B
MyFrame$PaintThread.class 759B
IFrame2$PaintThread.class 754B
IFrame3$PaintThread.class 754B
MyFrame$PaintThread.class 754B
IFrame$PaintThread.class 748B
MyFrame.class 730B
MyFrame$1.class 686B
IFrame2$1.class 681B
MyFrame$1.class 681B
IFrame3$1.class 681B
IFrame$1.class 675B
Constant.class 359B
Constant.class 357B
.classpath 301B
variablesAndContainers.dat 859B
Containers.dat 12B
e9.gif 1KB
e9.gif 1KB
e10.gif 1KB
e8.gif 1KB
e10.gif 1KB
e8.gif 1KB
e7.gif 1KB
e7.gif 1KB
e11.gif 1KB
e11.gif 1KB
e6.gif 1KB
e6.gif 1KB
e12.gif 1KB
e12.gif 1KB
e5.gif 1KB
e5.gif 1KB
e4.gif 1KB
e4.gif 1KB
e13.gif 1022B
e13.gif 1022B
e3.gif 846B
e3.gif 846B
e14.gif 814B
e14.gif 814B
e2.gif 565B
e2.gif 565B
e15.gif 460B
e15.gif 460B
e1.gif 312B
e1.gif 312B
e16.gif 280B
e16.gif 280B
properties.index 57B
version.ini 26B
invalidArchivesCache 4B
org.eclipse.osgi-3.5.1.R35x_v20091005.jar 1.08MB
org.springframework.context-3.0.1.RELEASE-A.jar 642KB
org.springframework.beans-3.0.1.RELEASE-A.jar 535KB
com.springsource.org.apache.log4j-1.2.15.jar 387KB
org.springframework.osgi.core-1.2.1.jar 354KB
org.springframework.core-3.0.1.RELEASE-A.jar 347KB
com.springsource.edu.emory.mathcs.backport-3.1.0.jar 328KB
com.springsource.net.sf.cglib-2.1.3.jar 321KB
org.springframework.aop-3.0.1.RELEASE-A.jar 313KB
org.springframework.osgi.extender-1.2.1.jar 118KB
org.springframework.context.support-3.0.1.RELEASE-A.jar 98KB
org.springframework.osgi.io-1.2.1.jar 35KB
com.springsource.org.objectweb.asm-2.2.3.jar 35KB
org.springframework.osgi.extensions.annotation-1.2.1.jar 24KB
com.springsource.slf4j.api-1.5.6.jar 22KB
com.springsource.slf4j.org.apache.commons.logging-1.5.6.jar 17KB
com.springsource.slf4j.log4j-1.5.6.jar 10KB
com.springsource.org.aopalliance-1.0.0.jar 5KB
PlaneGame.java 3KB
IFrame3.java 2KB
MyFrame.java 2KB
IFrame.java 2KB
Plant.java 1KB
IFrame2.java 1KB
Plane.java 1KB
IFrame4.java 1KB
IFrame4.java 1KB
Sun.java 1KB
MyFrame.java 937B
Bullet.java 783B
Start.java 593B
Explode.java 589B
共 198 条
- 1
- 2
资源评论
zhaoxiaozhao622
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言基础-C语言编程基础之Leetcode编程题解之第30题串联所有单词的子串.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第29题两数相除.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第28题找出字符串中第一个匹配项的下标.zip
- 实验报告模板(1).docx
- C语言基础-C语言编程基础之Leetcode编程题解之第26题删除有序数组中的重复项.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第25题K个一组翻转链表.zip
- hnu计算机系统作业-计算机系统基础课程大作业.zip
- 树莓派app.apk
- C++的基于同态加密技术的匿名电子投票系统源码.zip
- SW建模格式图.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功