package cn.bjsxt.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.bjsxt.util.Constant;
import cn.bjsxt.util.GameUtil;
import cn.bjsxt.util.MyFrame;

public class PlaneGameFrame extends MyFrame {
	Image bg = GameUtil.getImage("images/bg.jpg");
	Plane p = new Plane("images/plane.png",50,50);
	ArrayList  bulletList = new ArrayList();   //ʱδѧݲӡԺѧˣǿҽϡ
	
	Date startTime;
	Date endTime;
	
	Explode bao;
	
	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 = b.getRect().intersects(p.getRect());
			if(peng){
				p.setLive(false);  //ɻ
				if(bao==null){
					endTime = new Date();
					bao = new Explode(p.x,p.y);
				}
				bao.draw(g);
				
				break;
			}
		}
		
		if(!p.isLive()){
			int period = (int)((endTime.getTime()-startTime.getTime())/1000);
			printInfo(g, "ʱ䣺"+period+"", 20, 120, 260, Color.white);
			
			switch (period/10) {
			case 0:
			case 1:
				printInfo(g, "", 50,100,200,Color.white);
				break;
			case 2:
				printInfo(g, "С", 50,100,200,Color.white);
				break;
			case 3:
				printInfo(g, "", 50,100,200,Color.yellow);
				break;
			case 4:
				printInfo(g, "", 50,100,200,Color.yellow);
				break;
			default:
				printInfo(g, "", 50,100,200,Color.yellow);
				break;
			}
			
			
		}
		
		
//		printInfo(g, "100", 10, 50, 50, Color.yellow);
		
	}
	
	
	/**
	 * ڴϴӡϢ
	 * @param g
	 * @param str
	 * @param size
	 */
	public void printInfo(Graphics g,String str,int size,int x,int y,Color color){
		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 PlaneGameFrame().launchFrame();
	}
	
	
	public void launchFrame(){
		super.launchFrame();
		//Ӽ̵ļ
		addKeyListener(new KeyMonitor());
		
		//һӵ
		for(int i=0;i<35;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.addDirection(e);
		}

		@Override
		public void keyReleased(KeyEvent e) {
			p.minusDirection(e);
		}
		
	}
	
	
	
}

@@ -531,24 +531,8 @@
 ;   
-//%CA%B1%CE%B4%D1%A7%DD%B2%D3%A1%D4%BA%D1%A7%CB%A3%C7%BF%D2%BD%CF%A1%0D%0A%09
 %0D%0A%09D
@@ -859,11 +859,8 @@
 );  
-//%C9%BB
 %0D%0A%09%09
@@ -1108,10 +1108,13 @@
 g, %22
-%CA%B1%E4%A3%BA
+Time%EF%BC%9A
 %22+pe
@@ -1119,16 +1119,22 @@
 period+%22
+Second
 %22, 20, 1
@@ -1221,32 +1221,35 @@
 %09%09printInfo(g, %22
+Bad
 %22, 50,100,200,Co
@@ -1307,9 +1307,12 @@
 g, %22
-%D0%A1
+Good
 %22, 5
@@ -1370,32 +1370,37 @@
 %09%09printInfo(g, %22
+Great
 %22, 50,100,200,Co
@@ -1447,32 +1447,40 @@
 %09%09printInfo(g, %22
+Wondeful
 %22, 50,100,200,Co
@@ -1536,16 +1536,22 @@
 nfo(g, %22
+Winner
 %22, 50,10
@@ -1617,141 +1617,25 @@
 %09%09%0D%0A
-//%09%09printInfo(g, %22100%22, 10, 50, 50, Color.yellow);%0D%0A%09%09%0D%0A%09%7D%0D%0A%09%0D%0A%09%0D%0A%09/**%0D%0A%09 * %DA%B4%CF%B4%D3%A1%CF%A2%0D%0A%09 * @param g%0D%0A%09 * @param str%0D%0A%09 * @param size%0D%0A%09 */
+%0D%0A%09%09%0D%0A%09%7D%0D%0A%09%0D%0A%09%0D%0A%09
 %0D%0A%09p
@@ -1783,16 +1783,30 @@
 w Font(%22
+Times New Roma
 %22,Font.B
@@ -2041,30 +2041,12 @@
 %0D%0A%09%09
-//%D3%BC%CC%B5%C4%BC%0D%0A%09%09addKeyListene
+%0D%0A%09%09
 r(ne
@@ -2073,12 +2073,8 @@
 %0D%0A%09%09
-//%D2%BB%D3%B5
 %0D%0A%09%09
@@ -2200,17 +2200,8 @@
 %09%0D%0A%09
-//%CE%AA%DA%B2%E0%A3%AC%D4%B7%CA%B9%E2%B2%BF%CD%A8
 %0D%0A%09c
@@ -2297,52 +2297,8 @@
  %7B%0D%0A
-//%09%09%09System.out.println(%22%C2%A3%22+e.getKeyCode());
 %0D%0A%09%09

Update PlaneGameFrame.java