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

📄 missile.java

📁 用纯java语言做的一个简单的坦克大战游戏
💻 JAVA
字号:
package com.zhoutenghn;

import java.awt.*;
import java.util.List;

public class Missile {
	int x, y;
	public static final int MX = 10;
	public static final int MY = 10;
	Tank.Direction dir;
	BeginPlay tc;
	private boolean good = true;
	public static final int WIDTH = 7;
	public static final int HEIGHT = 7;
    private boolean live = true ;
	public Missile(int x, int y, boolean good,Tank.Direction dir,BeginPlay tc) {
		this.x = x;
		this.y = y;
		this.dir = dir;
		this.tc = tc;
		this.good = good;
	}

	public void draw(Graphics g) {
		if(!live) {
			tc.missiles.remove(this);
			return;
		}
		Color c = g.getColor();
		g.setColor(Color.BLACK);
		g.fillOval(x, y, WIDTH, HEIGHT);
		g.setColor(c);
		move();
	}

	public void move() {
		switch (dir) {
		case L:
			x -= MX;
			break;
		case LD:
			x -= MX;
			y += MY;
			break;
		case DR:
			x += MX;
			y += MY;
			break;
		case R:
			x += MX;
			break;
		case RU:
			x += MX;
			y -= MY;
			break;
		case U:
			y -= MY;
			break;
		case D:
			y += MY;
			break;
		case UL:
			x -= MX;
			y -= MY;
			break;
		}
		if (x < 0||y <0 || x > BeginPlay.GAME_WIDE ||y > BeginPlay.GAME_HEIGHT)
		{
			live = false;
			tc.missiles.remove(this);
		}
	}
    public Rectangle getRect(){
    	return new Rectangle(x,y,this.WIDTH,this.HEIGHT);
    }
    public boolean hitted(Tank t){
    	if(this.getRect().intersects(t.getRect())&& t.isLive()&& 
    			this.good!= t.isGood() )
    	{
    		t.setLive(false);
    		this.live = false;
    		Explode e = new Explode(x,y,true,tc);
    		tc.explodes.add(e);
    		return true;
    	}
    	return false;
    }
    public boolean hittedTanks(List<Tank> tanks){
    	for(int i = 0;i < tanks.size();i++){
    		if(hitted(tanks.get(i))){
    			tanks.remove(i);
    			return true;
    		}
    	}
    	return false;
    }
	public boolean isLive() {
		return live;
	}
}

⌨️ 快捷键说明

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