亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? battlecity.java

?? Simple java game showing how to handle multi-threading.
?? JAVA
字號:
/** 
 * BattleCity
 *
 * @version	1.0
 * @author	Tanwani Anyangwe
 * @email	tanyan1@towson.edu
 * @url		http://tiger.towson.edu/users/tanyan1
 */
 
import java.awt.*;
import java.applet.*;
import java.awt.image.*;

import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;

import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

//Audio
import java.net.*;
import java.applet.AudioClip;

//for the Vector class
import java.util.*;

public class BattleCity extends Applet implements Runnable, KeyListener, MouseListener {

	int delay, counter;
    Thread animator;
	Image Buffer;
	Graphics gBuffer;
	Intro intro;
	Tank tank[];
	Shell myShell;	  
	
	Vector v;	//our vector variable, can store unlimited number of shells
	int index;	//Our vector index
	
    //how many tanks?
    static final int MAX=10;
	
	//Our game bearings (directions)
	static final int NORTH = 1;
	static final int EAST = 2;
	static final int SOUTH = 3;
	static final int WEST = 4;
	
	boolean gameOver, animateField, playerWon, startNew=false;
	int shieldsLeft, gameLevel, playerPoints, tanksLeft;
	Image img1, img2;
	String player1;
	Point target;
	Color bgColor = new Color(170,191,169);
	Rectangle rect1, rect2;
	
	// Sounds
	AudioClip	fire, crash, explosion, gong;

	public void init() {
		img1 = getImage(getDocumentBase(),"images/welcome1.gif");
		img2 = getImage(getDocumentBase(),"images/welcome2.gif");
		
		loadSounds();
		
		String str = getParameter("playerName");
		player1 = (str != null) ? str : "Player 1";
		
		delay = 100;
		gameOver = true;
		animateField = false;
		playerWon = false;
		
		Buffer = createImage(getSize().width,getSize().height);
		gBuffer = Buffer.getGraphics();
		
		intro = new Intro();
		intro.img1 = img1;
		intro.img2 = img2;
		
		tank = new Tank[MAX];
		initTanks();
		
		v = new Vector();
		
		this.setBackground(bgColor);
		this.addMouseListener(this);
		this.addKeyListener(this);
    }
	
	public void start() {animator = new Thread(this); animator.start();}

	public void run() {
		while (Thread.currentThread() == animator) {
		    repaint();
			simulateTanks();
			
			try { Thread.sleep(delay); } 
			catch (InterruptedException e) { break; }
		}
    }

    public void stop() { animator = null; }
	
	public void update(Graphics g) { paint(g); }
	
	public void paint(Graphics g)
	{
		gBuffer.clearRect(0,0,400,360);		
		drawBg();
		
		if (!intro.opened) { intro.paint(gBuffer); if(intro.opening) {intro.move();} }
		
		paintTanks(); //paint all tanks	
		paintShells(); //paint all shells	
		
		g.drawImage(Buffer,0,0,this); 	
		
		//showStatus("Game Level: " + new Integer(gameLevel).toString() + "  Tanks Left: " + new Integer(tanksLeft).toString());
	}

	public void mouseClicked(MouseEvent e){} 
	public void mouseEntered(MouseEvent e){} 
	public void mouseExited(MouseEvent e){}
	public void mousePressed(MouseEvent e){} 
	public void mouseReleased(MouseEvent e){
		Rectangle r1 = new Rectangle(100,90,200,180);
		if(gameOver && gameLevel==0){
			if(r1.contains(e.getX(), e.getY())){ 
				if(!intro.opened) {
					intro.opening=true; 
					gong.play();
				}  
				else {newGame();}
			}
		}
	} 

	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		switch (keyCode) {
			case 38: tank[0].turn(1);	break; 
            case 39: tank[0].turn(2);	break;
            case 40: tank[0].turn(3);	break;
            case 37: tank[0].turn(4);	break;
            case 65: tank[0].isMoving = true;	break;
            case 32: fireShell(0);	break;
        }   
    }
	
    public void keyReleased(KeyEvent e) {
		int keyCode = e.getKeyCode();
		switch (keyCode) {
          case 65: tank[0].isMoving = false;	break;
        }   
    }
	
    public void keyTyped(KeyEvent e) { }
			
	void loadSounds(){
		try {
			fire = getAudioClip(new URL(getDocumentBase(), "sounds/fire.au"));
			crash = getAudioClip(new URL(getDocumentBase(), "sounds/crash.au"));
			explosion = getAudioClip(new URL(getDocumentBase(), "sounds/explosion.au"));
			gong = getAudioClip(new URL(getDocumentBase(), "sounds/gong.au"));
		}
		catch (MalformedURLException e) {}

		fire.play();  fire.stop();
		explosion.play();  explosion.stop();
		crash.play();   crash.stop();
		gong.play();   gong.stop();
	}
	
	void drawBg(){
		
		gBuffer.setColor(bgColor);
		gBuffer.fillRect(0,0,400,360);
		gBuffer.setColor(Color.black);
		gBuffer.drawRect(2,2,394,354);		
		
		gBuffer.setColor(Color.gray);
		gBuffer.setFont(new Font("Arial", Font.BOLD, 150));
		gBuffer.drawString(new Integer(gameLevel).toString() , 150, 220); 		

		if(gameLevel==3 && !gameOver )animateField=true;
		
		if (animateField){
			float h, s, b;
			int i;
			for (i=0; i<400; i++){
				h = (float)Math.random(); s = (float)Math.random(); b = (float)Math.random();
				gBuffer.setColor(Color.getHSBColor(h, s, b));
				gBuffer.drawLine(i,0,i,360);
				i+=20;
			}	
			for (i=0; i<360; i++){
				h = (float)Math.random(); s = (float)Math.random(); b = (float)Math.random();
				gBuffer.setColor(Color.getHSBColor(h, s, b));
				gBuffer.drawLine(0,i,400,i);
				i+=20;
			}	
		}

		if(gameOver){
			if(gameLevel!=0)endGame(!playerWon);
			else {
				gBuffer.setFont(new Font("Arial", Font.BOLD, 18));
				gBuffer.setColor(Color.blue);
				gBuffer.drawString("Start!",185,175); 
				gBuffer.drawRect(170,150,80,40);
			}
			
			gBuffer.setColor(Color.red);
			gBuffer.setFont(new Font("Arial", Font.BOLD, 16));
			gBuffer.drawString("1. Key \"A\" to move tank",10,20); 			
			gBuffer.drawString("2. Key \"Space\" to fire shells",10,40); 			
			gBuffer.drawString("3. Arraow keys to change direction",10,60); 			
			gBuffer.drawString("4. Player's tank is green",10,80); 			
			
		}
		else{
			if(startNew)newGame();
		}
	}
	
	void newGame(){
		inactivateTanks(2);
		gameLevel = 0;
		playerPoints = 0;
		gameOver = false;
		animateField=false;		
		nextLevel();
	}
	
	void endGame(boolean pcWon){
		gameOver = true;
		inactivateTanks(1);
		gBuffer.setColor(Color.yellow);
		gBuffer.setFont(new Font("Arial", Font.BOLD, 20));
		gBuffer.drawString("Game Over: ",115,140); 		
		if(pcWon){gBuffer.drawString("You Lost",240,140); }
		else {gBuffer.drawString("You Won",240,140); }
		gBuffer.setColor(Color.orange);
		gBuffer.drawString(player1 +"'s Points: " + new Integer(playerPoints).toString() ,150,240);		
	}
	
	void endLevel(){				
		if(gameLevel>2){ 
			gameOver = true;
			playerWon = true;
			startNew=true;
		}
		else {nextLevel();}
	}
	
	void nextLevel(){		
		gameLevel++;
		shieldsLeft = 3; 
		tanksLeft = 3;
		gBuffer.setColor(Color.yellow);
		counter = 1000;
		initGameLevel();
	}
	
	void playerHit(){
		shieldsLeft -= 1; 
		if(shieldsLeft<0){
			tank[0].explode();
			gameOver = true;
			playerWon = false;
			startNew=true;
			inactivateTanks(0);
		}
	}
	void enemyHit(int i){
		tanksLeft -= 1; 
		playerPoints += tank[i].moveBy;
		tank[i].explode();
		if(tanksLeft<1)endLevel();		
	}
	
	void initGameLevel(){
		int i;
		switch (gameLevel) {
			case 1: for(i=0;i<4;i++){tank[i].isAlive = true;tank[i].isMoving = true;} break; 
            case 2: for(i=4;i<7;i++){tank[i].isAlive = true;tank[i].isMoving = true;} break; 
            case 3: for(i=7;i<10;i++){tank[i].isAlive = true;tank[i].isMoving = true;} break; 
        }  		
		tank[0].isAlive = true; //Keep player alive incase they start at a higher level
		tank[0].isMoving = false;
	}
	
	void initTanks(){
		int x[] = {340,320,10,80,10,340,320,10,80,10};
		int y[] = {300,10,10,120,310,300,10,10,120,310};
		int d[] = {1,4,3,2,1,1,4,3,2,1};
		int s[] = {5,5,5,5,10,8,8,10,10,20};
		int mf[] = {1,1,1,1,2,2,2,3,3,4};
		Color ct = new Color(139,0,0);
		Color c[] = {new Color(0,113,0),ct,ct,ct,Color.red,Color.orange,Color.orange,Color.red, Color.red, Color.black};
		for(int i=0;i<MAX;i++){			
			tank[i] = new Tank(x[i],y[i],c[i],s[i],d[i],mf[i]);
		}
	}
	
	void paintTanks(){			
		for(int i=0;i<MAX;i++){
			if(tank[i].isAlive)tank[i].paint(gBuffer);
		}
	}
	
	void inactivateTanks(int n){			
		for(int i=0;i<MAX;i++){
			if(n==0)tank[i].isAlive=false;
			if(n==1)tank[i].isMoving=false;
			if(n==2)tank[i].exploded=false;
		}
	}
	
	void paintShells(){
		int prevIndex=-1, currIndex;
        for(int i=0;i<index;i++)
        {
            //the element stored in the vector at index position i
            //is casted to a Shell object and assigned to
            //the variable myShell, to access it's methods!
            myShell=(Shell)v.elementAt(i);

			if(myShell.isAlive){
				myShell.move();
				myShell.paint(gBuffer);
				for(int j=0;j<MAX;j++){
					if(tank[j].isAlive){
						rect1 = new Rectangle(tank[j].x,tank[j].y,35,35);
						if(rect1.contains(myShell.x,myShell.y)){
							tankHit(j);
							myShell.isAlive = false;
							explosion.play();
						}
					}
				}
			}
        }
	}
	
	void tankHit(int i){		
		if(i==0)playerHit();
		else enemyHit(i);		
	}
	
	void simulateTanks(){
		for(int i=0;i<MAX;i++){
			if(tank[i].isAlive){
				handleIntersections();
				simulateMovement(i);
				if(i!=0) simulateFire(i);
			}
		}
	}
	
	void handleIntersections()
	{
		//we iterate through all the tanks, checking if they meet at an intersection
		for(int i=0;i<MAX;i++)
			for(int j=0;j<MAX;j++)
				{
					if( tank[i].isAlive && tank[j].isAlive && (i!=j))
					{								
						if( collide(tank[i], tank[j])  )
						{
							tank[i].turnAround();
							tank[j].turnAround();
							tank[i].move();
							tank[j].move();
						}
					}
				}
	}
	
	boolean collide(Tank t1, Tank t2)
	{
		rect1 = new Rectangle(t1.x, t1.y, t1.tankWidth(), t1.tankHeight()); 
		rect2 = new Rectangle(t2.x, t2.y, t2.tankWidth(), t2.tankHeight()); 
		return rect1.intersects(rect2);
	}
	
	void simulateMovement(int i){
		
		if(tank[i].isMoving){tank[i].move();}
		else{	
			if(i!=0){
				tank[i].turnAround();
				tank[i].isMoving = true;
			}
		}		
	}
	
	void simulateFire(int i){
		boolean canfire = false;
		int cord;
		rect2 = new Rectangle(tank[0].x,tank[0].y,tank[0].tankWidth(),tank[0].tankHeight());
		
		if(tank[i].direction==1 || tank[i].direction==3 ){
			cord = tank[i].x+((int)tank[i].tankWidth()/2)-2;
			rect1 = new Rectangle(cord,0,3,360);
		}else {
			cord = tank[i].y+((int)tank[i].tankHeight()/2)-2;
			rect1 = new Rectangle(0,cord,400,3);
		}
		
		if (rect1.intersects(rect2)){
			if(gameLevel>1 )simulateDirection(i);
			canfire = true;
		}
		
		if(canfire)fireShell(i); 
	}
	
	void simulateDirection(int i){
		
		if(tank[i].x > tank[0].x){
			if(tank[i].direction==EAST && tank[0].direction==EAST)tank[i].turnAround();
		}						
		if(tank[i].x < tank[0].x){
			if(tank[i].direction==WEST && tank[0].direction==WEST)tank[i].turnAround();
		}	
		if(tank[i].y > tank[0].y){
			if(tank[i].direction==SOUTH && tank[0].direction==SOUTH)tank[i].turnAround();
		}						
		if(tank[i].y < tank[0].y){
			if(tank[i].direction==NORTH && tank[0].direction==NORTH)tank[i].turnAround();
		}	
	}
	
	void fireShell(int i)
    {
		int cnt=0;		
		for(int n=0;n<index;n++) {
            myShell=(Shell)v.elementAt(n);
			if(myShell.tankIndex==i && myShell.isAlive) cnt++;
			if(cnt==tank[i].maxFire) return;
		}
		 
		int dir = tank[i].direction;
        myShell = new Shell();
        myShell.direction = dir;
		myShell.tankIndex = i;

		switch (dir) {
            case NORTH: myShell.w=3; myShell.h=10; myShell.x=tank[i].x+17; myShell.y=tank[i].y-10; break;
            case EAST:	myShell.w=10; myShell.h=3; myShell.x=tank[i].x+40; myShell.y=tank[i].y+17; break;
            case SOUTH: myShell.w=3; myShell.h=10; myShell.x=tank[i].x+17; myShell.y=tank[i].y+40; break;
            case WEST:  myShell.w=10; myShell.h=3; myShell.x=tank[i].x-10; myShell.y=tank[i].y+17; break;
        }    
		fire.play();
		
        //we add a new element to the vector
        v.addElement(myShell);

        //our index number is incremented, to keep track of the number
        //of created shells
        index++;
    }
}








?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区三区免费| 国产一区二三区| 91精品国产综合久久久久久久久久| 亚洲欧美日韩系列| 欧美亚洲一区二区在线观看| 午夜伦理一区二区| 日韩欧美成人一区二区| 国产一区在线不卡| 国产精品美日韩| 在线观看不卡一区| 免费av成人在线| 亚洲国产高清在线| 一本大道av一区二区在线播放 | 久久99久久久欧美国产| 久久综合av免费| 91色综合久久久久婷婷| 午夜影视日本亚洲欧洲精品| 日韩精品一区二区三区四区| 国产成人精品综合在线观看| 一区二区三区色| 日韩片之四级片| www.综合网.com| 三级久久三级久久久| 国产午夜精品美女毛片视频| 在线精品视频免费观看| 久久99精品久久久久久动态图| 中文字幕欧美日韩一区| 欧美午夜精品电影| 国产麻豆成人精品| 亚洲一区二区三区在线| 亚洲精品在线一区二区| 91麻豆国产福利在线观看| 日韩精品乱码av一区二区| 国产欧美精品一区aⅴ影院| 在线观看一区二区视频| 国产一区二区三区视频在线播放| 亚洲视频一区二区在线| 欧美成人vr18sexvr| 91丨国产丨九色丨pron| 九九九久久久精品| 亚洲一区精品在线| 欧美精彩视频一区二区三区| 欧美久久免费观看| 99久久精品免费看国产| 老司机精品视频线观看86| 亚洲免费观看高清在线观看| 欧美mv日韩mv国产网站app| 欧洲精品一区二区| 懂色av一区二区三区蜜臀 | 3751色影院一区二区三区| fc2成人免费人成在线观看播放| 日韩精品一区第一页| 亚洲女女做受ⅹxx高潮| 国产蜜臀97一区二区三区 | 精品国产乱码久久久久久牛牛| 日本精品裸体写真集在线观看| 国产毛片一区二区| 久久99久久久久| 日韩av中文字幕一区二区| 亚洲一区二区三区精品在线| 国产精品久久久久久久久免费桃花 | 北条麻妃一区二区三区| 久久99热99| 美女精品自拍一二三四| 日韩极品在线观看| 午夜欧美视频在线观看 | 日韩毛片在线免费观看| 国产亚洲精品精华液| 精品久久五月天| 91精品国产综合久久久久久久久久 | jiyouzz国产精品久久| 国产成人综合亚洲网站| 国产综合色在线视频区| 精品一区二区三区蜜桃| 久久精品噜噜噜成人av农村| 视频一区二区不卡| 男男视频亚洲欧美| 日本人妖一区二区| 久久国产精品无码网站| 卡一卡二国产精品 | 884aa四虎影成人精品一区| 欧美日韩一区中文字幕| 91精品综合久久久久久| 欧美片网站yy| 日韩免费电影一区| 久久精品在这里| 国产精品乱码一区二三区小蝌蚪| 中文字幕在线观看一区二区| 亚洲蜜臀av乱码久久精品蜜桃| 亚洲精品成人精品456| 亚洲午夜在线电影| 欧美aaaaa成人免费观看视频| 久草热8精品视频在线观看| 国产精品一区二区久久不卡 | 91丨九色porny丨蝌蚪| 色国产精品一区在线观看| 欧美日韩不卡一区二区| 日韩欧美中文字幕一区| 久久久久久97三级| 亚洲人成7777| 日韩国产欧美在线播放| 国产麻豆欧美日韩一区| 91在线精品一区二区三区| 欧美亚洲动漫精品| 精品日韩99亚洲| ㊣最新国产の精品bt伙计久久| 亚洲一区免费视频| 国内精品国产成人| 91香蕉视频mp4| 欧美一区午夜视频在线观看 | 中文字幕在线观看一区二区| 亚洲福利电影网| 国产精品综合av一区二区国产馆| av电影一区二区| 日韩一区二区在线观看视频播放| 久久免费国产精品| 亚洲图片欧美视频| 国产成人h网站| 欧美精品18+| 国产精品丝袜在线| 蜜臀av性久久久久蜜臀aⅴ流畅 | 久久国产精品99久久久久久老狼| 成人白浆超碰人人人人| 欧美一区日韩一区| 最好看的中文字幕久久| 麻豆精品国产传媒mv男同| 91免费视频观看| 精品福利视频一区二区三区| 亚洲在线中文字幕| 成人中文字幕在线| 日韩精品一区二区三区四区 | 日韩高清国产一区在线| 不卡一区二区三区四区| 日韩视频在线永久播放| 一区二区成人在线视频| 成人激情图片网| 精品国产三级电影在线观看| 亚洲一区二区欧美| 成人av电影在线| 精品盗摄一区二区三区| 视频一区二区三区在线| 色综合久久久网| 国产精品美女久久久久高潮| 久久狠狠亚洲综合| 4438亚洲最大| 亚洲18色成人| 在线观看亚洲成人| 亚洲女性喷水在线观看一区| 国产福利91精品一区二区三区| 欧美丰满一区二区免费视频 | 暴力调教一区二区三区| 久久精品视频一区二区三区| 日韩专区在线视频| 欧美日韩久久一区二区| 亚洲激情中文1区| 色婷婷综合久久久久中文| 亚洲国产精品99久久久久久久久| 精品一区二区久久久| 日韩三级视频中文字幕| 日韩成人一级片| 欧美丰满美乳xxx高潮www| 亚洲国产欧美一区二区三区丁香婷| 成人激情黄色小说| 国产精品毛片高清在线完整版| 国产成人免费高清| 国产女人18毛片水真多成人如厕| 精品写真视频在线观看| 精品国产伦一区二区三区观看方式 | 日韩精品欧美精品| 精品视频在线看| 无吗不卡中文字幕| 日韩一区二区三区视频在线| 日韩国产欧美在线观看| 欧美一区二区私人影院日本| 日韩电影在线免费看| 欧美一区二区视频在线观看| 免费在线视频一区| 欧美mv日韩mv| 国产成人aaa| 亚洲日本一区二区三区| 色噜噜狠狠色综合中国| 亚洲高清中文字幕| 欧美一区二区三区免费大片| 精品一区二区日韩| 国产校园另类小说区| 成人毛片视频在线观看| 亚洲精品少妇30p| 欧美日韩高清一区二区不卡| 男男gaygay亚洲| 国产日韩欧美麻豆| 色哟哟国产精品免费观看| 午夜精品福利一区二区蜜股av| 制服.丝袜.亚洲.中文.综合| 精品一区二区三区免费观看| 国产精品欧美久久久久一区二区| 日本高清视频一区二区| 免费人成黄页网站在线一区二区| 国产亚洲综合在线| 在线观看国产精品网站| 久久成人免费日本黄色|