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

📄 gmcomponent.java

📁 联机坦克游戏
💻 JAVA
字号:
/*
 * Created on 2005-1-24
 *
 * Tankgame
 */
package components;

import java.util.*;
import shape.IShape;

/**
 * @author AnSen
 * 
 * base gmcomponent
 */
public abstract class GmComponent {

	protected long lLife = -1;//the life time (-1 is never dead)

	protected Vector vContainer = null;//the list of components

	protected double ptX = 0;

	protected double ptY = 0;

	//protected Vector vFrame = new Vector();//the shape of component

	protected IShape ishpframe = null;

	protected Vector vGmListeners = new Vector();//the listener list

	/**
	 * @param life
	 * @param ptX
	 * @param ptY
	 * @param container
	 */
	public GmComponent(long life, double ptX, double ptY, Vector container) {
		lLife = life;
		this.ptX = ptX;
		this.ptY = ptY;
		this.vContainer = container;
		initObject();
	}

	public GmComponent() {
		initObject();
	}

	public boolean isViva() {
		if (lLife == -1) {
			return true;
		} else {
			return lLife > 0;
		}
	}

	public IShape getFrame() {//get the physic mode of the object;
		return ishpframe;
	}

	public void initObject() {
		for (int i = 0; i < vGmListeners.size(); i++) {
			((IGmListener) vGmListeners.get(i)).initProformed();
		}
	}

	public void removeOject() {
		for (int i = 0; i < vGmListeners.size(); i++) {
			((IGmListener) vGmListeners.get(i)).removeProformed();
		}
		vContainer.remove(this);
	}

	public void updateOject() {
		for (int i = 0; i < vGmListeners.size(); i++) {
			((IGmListener) vGmListeners.get(i)).updateProformed();
		}
		if (lLife != -1) {
			lLife--;
		}
		if (!isViva()) {
			removeOject();
		}
	}

	/**
	 * @return Returns the lLife.
	 */
	public long getLLife() {
		return lLife;
	}

	/**
	 * @param life
	 *            The lLife to set.
	 */
	public void setLLife(long life) {
		lLife = life;
	}

	/**
	 * @return Returns the vContainer.
	 */
	public Vector getContainer() {
		return vContainer;
	}

	/**
	 * @param container
	 *            The vContainer to set.
	 */
	public void setContainer(Vector container) {
		vContainer = container;
	}

	/**
	 * @return Returns the PositionX.
	 */
	public int getPositionX() {
		return ((int) ptX);
	}

	/**
	 * @return Returns the PositionY.
	 */
	public int getPositionY() {
		return ((int) ptY);
	}

	/**
	 * @param ptPosition
	 *            The ptPosition to set.
	 */
	public void setPtPosition(double x, double y) {
		this.ptX = x;
		this.ptY = y;
	}

	/**
	 * @return Returns the vShapes of view.
	 */
	//public Vector getView();
	public void addGmListener(IGmListener gls) {
		this.vGmListeners.addElement(gls);
	}

	public boolean removeListener(IGmListener gls) {
		return vGmListeners.remove(gls);
	}

	public void removeAllListener() {
		vGmListeners.removeAllElements();
	}

	/**
	 * @return Returns the ptX.
	 */
	public double getPtX() {
		return ptX;
	}

	/**
	 * @return Returns the ptY.
	 */
	public double getPtY() {
		return ptY;
	}

	public boolean isSuperpose(int left, int top, int width, int height) {
		return this.ishpframe.isSuperpose(left, top, width, height);
	}
	
	public void damnify(int iDamage){
		//System.out.println("bomb");
		//listener proforme
		for (int i = 0; i < this.vGmListeners.size(); i++) {
			Object obj = vGmListeners.get(i);
			if (obj instanceof ITankListener) {
				((ITankListener) obj).damnifyProformed(iDamage);
			}
		}
	}
}

⌨️ 快捷键说明

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