首页>代码>java swing开发打飞机的小游戏源代码下载>/PlaneGame/src/com/leng/frame/battleGame.java
package com.leng.frame;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;

import com.leng.Util.Control;
import com.leng.Util.GameMap;
import com.leng.Util.InciseImage;
import com.leng.Util.Kbordlistener;
import com.leng.role.Monster;
import com.leng.role.MyPlan;

/***
 * 自制打飞机游戏 战斗主界面
 * @author 黄昏的阳光
 * 2013-8-31
 *
 */
public class battleGame extends JFrame implements Runnable {
	/**存放所有角色的集合*/
	public static List<Monster> list=new ArrayList<Monster>();
	/**游戏是否运行**/
	public static boolean isRun=true;
	/**地图对象*/
	private GameMap gamemap=new GameMap();
	/**媒体追踪器*/
	public MediaTracker  media;
	/**双缓冲画笔*/
	private Graphics  memoryGraphics;
	/**双缓冲画布*/
	private Image memoryImage;
	/**监听器 对象*/
	public Kbordlistener key=new Kbordlistener();
	/**我的灰机对象*/
	public static MyPlan my=new MyPlan(100, 550);
	/**玩家得分*/
	public static int pointer=0;
	/**控制器对象*/
	Control con=new Control();
	public battleGame() {
		//设置窗体大小
		this.setSize(300, 600);
		//设置窗体名字
		this.setTitle("灰机");
		//设置窗体默认居中
		this.setLocationRelativeTo(null);
		//设置框体大小不可改变
		this.setResizable(false);
		//设置窗体关闭 程序结束
		this.setDefaultCloseOperation(3);
		//设置可见
		this.setVisible(true);
		//初始化 媒体追踪器
		media=new MediaTracker(this);
		//初始化所有图片
		 InciseImage.inci(media);
		 
		 //添加监听器
		this.addKeyListener(key);
		//添加 我的灰机
		this.list.add(my);
		 
		 /**
			 * 双缓冲画布和画笔的初始化
			 */
			/**900*700的内存画布*/
			this.memoryImage=this.createImage(300,600);
			/**内存画笔*/
			this.memoryGraphics=this.memoryImage.getGraphics();
		
	}
	
	@Override
	public void run() {
		while(isRun){
			this.draw(this.getGraphics());
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	/**
	 * 绘制所有图片的方法
	 * */
	private void draw(Graphics g){
		/**刷怪*/
		con.control();
		gamemap.drawMyself(memoryGraphics);
		for(int i=0;i<list.size();i++){
			Monster m=list.get(i);
			if(m!=null){
				m.drawMYself(memoryGraphics);
			}
		}
		//绘制玩家得分
		memoryGraphics.drawString("得分:"+battleGame.pointer, 20, 50);
		g.drawImage(this.memoryImage,0,0,this); 
	}
	
	public static void main(String[] args) {
		  battleGame bate=new battleGame();
		  Thread th=new Thread(bate);
		  		th.start();
	}



}
最近下载更多
微信网友_6550471470403584  LV1 2023年7月6日
2017143155  LV12 2023年6月27日
yangyanlong  LV1 2023年5月19日
1739332236  LV1 2023年2月23日
冯不二  LV1 2023年2月13日
可是不知道么  LV23 2021年11月29日
thinkerkkk  LV2 2021年6月22日
ldx1234  LV4 2021年5月22日
benbosn  LV15 2021年5月5日
 LV1 2021年4月14日
最近浏览更多
ClydeSon  LV5 2023年12月28日
1112WHQ  LV7 2023年11月3日
jiemomo  LV12 2023年10月19日
微信网友_6568795145506816  LV1 2023年7月19日
微信网友_6550471470403584  LV1 2023年7月6日
2017143155  LV12 2023年6月26日
暂无贡献等级
SILKYYY 2023年5月25日
暂无贡献等级
yangyanlong  LV1 2023年5月19日
小安同学  LV7 2023年5月11日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友