천둥, 번개 놀이, 비행기 충돌, 핏덩어리 실현...

             ,    ,        ,,  ,      ,      ,         ,
        ,            !        

package     ;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.LayoutManager;
import java.awt.RenderingHints.Key;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JPanel;


/**
 *   ,               ,
 * @author yan
 *
 */
public class WarUI extends Frame{
	public static final int WIDTH=410;
	public static final int HEIGHT=600;
	public ImageIcon img;
	public ImageIcon img2;
	public static WarUI warui;
	public boolean p=true;
	public static List planes = new ArrayList();//       
	public static List bullets = new ArrayList();//     
	public static List explodes=new ArrayList();//    
	public static int score=0;//  
	private Image offScreenImage = null;//         ,       
	public  Plane myplane=new Plane(150,500,warui,40,true);
	private Random random=new Random();
	private Blood b=new Blood();//      
	public void lauchFrame() {
		setTitle("    ");
		setBounds(380, 100, WIDTH, HEIGHT);
		//      , ,        
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		//      
		Image a=this.getToolkit().getImage("  \\Icon.png");
		this.setIconImage(a);
		img=new ImageIcon("  \\back.jpg");//  ,getImage      Image  ,repaint     paint  
		img2=new ImageIcon("  \\back2.jpg");//  ,getImage      Image  ,repaint     paint  
		setResizable(false);
		setVisible(true);
		MyKeyListener mkl=new MyKeyListener();
		this.addKeyListener(mkl);
		new Thread(new PaintThread()).start();
	}
	
	public static void main(String[] args) {
		warui =new WarUI();
		warui.lauchFrame();
		
	}	
	/**
	 	*     ,     
	 	*         ,         。                 ;
	    *       repaint   ,      update  paint  
	 */

		public void update(Graphics g) {
			if (offScreenImage == null) {
				offScreenImage = this.createImage(WIDTH, HEIGHT);
			}
			//         
			Graphics gOffScreen = offScreenImage.getGraphics();
			Color c = gOffScreen.getColor();
			gOffScreen.setColor(Color.blue);
			gOffScreen.fillRect(0, 0, WIDTH,HEIGHT);
			gOffScreen.setColor(c);
			paint(gOffScreen);//        
			g.drawImage(offScreenImage, 0, 0, null);//      
		}
		/**
		 *        repaint  ,      ,  ,  ,    ,           
		 */
	public void paint(Graphics g){
		//	              
		if(score>5000){
			g.drawImage(img2.getImage(), 0, 0, warui);
		}else{
			g.drawImage(img.getImage(), 0, 0, warui);
		}
		if(!myplane.isLive()){
			g.setColor(Color.red);
			Font f = g.getFont();
			g.setFont(new Font("  ",Font.BOLD,60));
			g.drawString("GAME  OVER!!!", 20, 300);
			g.setFont(f);
			g.drawString("   B,     C!!!", 22, 340);
			p=false;
			
		}
		myplane.draw(g);
		myplane.move();
		myplane.pengplane(planes);
		myplane.eat(b);
		
		/**
		 *    /     
		 */
		if (planes.size()<3 ) {
			for (int j = 0; j < 3; j++) {
				Plane p = new Plane(false, warui);
				planes.add(p);
			}
		}
		if (planes.size() != 0) {
			for (int i = 0; i < planes.size(); i++) {
				Plane diren = planes.get(i);
				diren.draw(g);
				
				diren.dmove();
				int r1=random.nextInt(200);
				if(r1==20)
				diren.dfire();
			}
		}
		g.setColor(Color.BLUE);
		g.drawString("         :"+bullets.size(), 20,50);
		g.drawString("     :"+planes.size(), 20, 70);
		g.drawString("    :"+score, 20, 90);
		g.drawString("A   ,P   ", 20, 110);
		g.drawString("C    ,B   :", 20, 130);
		g.setColor(Color.BLACK);
		for(int i=0;i

좋은 웹페이지 즐겨찾기