⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 missile.java

📁 J2SE坦克大战源码 分为24个版本
💻 JAVA
字号:
import java.awt.*;

public class Missile {
	
	int x;
	int y;
	MyTank.Direction dir;
	public static final int XSPEED = 10;
	public static final int YSPEED = 10;
	public static final int WI = 10;
	public static final int HE = 10;
	private boolean live = true;
	TankClient tc = null;
	
	public Missile(int x, int y, MyTank.Direction dir,TankClient tc) {
		this.x = x;
		this.y = y;
		this.dir = dir;
		this.tc = tc;
	}
	
	public void draw(Graphics g){
		if(!live)return;
		
		Color c = g.getColor();
		g.setColor(Color.BLACK);
		g.fillOval(x, y, 11, 11);
		g.setColor(c);				
		move();
	}
	
	public void move(){	
		switch(dir){
		case U:
			y -= YSPEED;
		break;
		case RU:
			x += XSPEED;
			y -= YSPEED;
		break;
		case R:
			x += XSPEED;
		break;
		case RD:
			x += XSPEED;
			y += YSPEED;
		break;
		case D:
			y += YSPEED;
		break;
		case LD:
			x -= XSPEED;
			y += YSPEED;
		break;
		case L:
			x -= XSPEED;
		break;
		case LU:
			x -= XSPEED;
			y -= YSPEED;
		break;
		case STOP:		
		break;
		
		}	
		
		if( x<0 || y< 0 || x > TankClient.GAME_WEIGHT || y>TankClient.GAME_HEIGHT){
			live = false;
		}
	}
	
	public Rectangle getRect(){
		return new Rectangle(x,y,WI,HE);
	}
	
	public boolean hitTank(MyTank t){
		if(this.getRect().intersects(t.getRect()) && t.isLive() ){
			t.setLive(false);
			Explode ep = new Explode(x,y,tc);
			tc.explodes.add(ep);
			setLive(false);
			return true;
		}
			return false;
	}

	public boolean isLive() {
		return live;
	}

	public void setLive(boolean live) {
		this.live = live;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -