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

📄 fleetdo.java

📁 Java mulitplayer strategy game. Adaptation of KDE Galaxy Conquest. (rules are changed - but still th
💻 JAVA
字号:
package net.sf.jawp.game.domain;

import net.sf.jawp.api.domain.Fleet;
import net.sf.jawp.api.domain.GameSpeed;
import net.sf.jawp.api.domain.Realm;
import net.sf.jawp.api.domain.SpaceCoords;
import net.sf.jawp.util.Log;

/**
 * fleet
 * @author jarek
 * @version $Revision: 1.17 $
 *
 */
public final class FleetDO extends Fleet
{
	private static final Log LOG = Log.getLog(FleetDO.class );
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private int size;
	
	private float stepsToTarget = 0;
	
	public FleetDO(final long k, final Realm owner)
	{
		super(k, owner);
	}


	public void incFleet(final int nmb)
	{
		setSize( getSize() + nmb);
	}

	/**
	 * 	calculates movement for fleet
	 *
	 */
	public void calculateDirection(final GameSpeed gSpeed)
	{
		assert LOG.debug("target is:" + this.getTargetPosition().toString());
		assert LOG.debug("pos is:" + this.getPosition().toString());
		final float difx = this.getTargetPosition().getX() - this.getPosition().getX();
		final float dify = this.getTargetPosition().getY() - this.getPosition().getY();
		final float difz = this.getTargetPosition().getZ() - this.getPosition().getZ();
		
		final double dist2 = (difx * difx) + (dify * dify) + (difz * difz);
		//assert LOG.debug("dist2 is:" + dist2);
		final double dist = Math.sqrt( dist2);
		//assert LOG.debug("dist is:" + dist);
		
		stepsToTarget = (float)(dist / gSpeed.getBaseFleetSpeed());
		//assert LOG.debug("steps is:" + stepsToTarget);
		
		final SpaceCoords dir = new SpaceCoords( (difx / stepsToTarget), 
				(dify / stepsToTarget), (difz / stepsToTarget) );
		setDirection(dir);
	}
	
	public void move(final GameSpeed gSpeed, final long timeSlice)
	{
		setPosition( getPosition().add( gSpeed.adjustMovement( timeSlice, getDirection()) ) );
		stepsToTarget -= gSpeed.getAdjustedStep(timeSlice);
		//assert LOG.debug( "steps to go:" + stepsToTarget );
	}
	
	public boolean hasFinishedMovement()
	{
		return this.stepsToTarget <= 0;
	}
	
	public void reduce(final int nm )
	{
		setSize( getSize() - nm);
	}
	
	public void land(final PlanetDO target)
	{
		this.setPosition( new SpaceCoords(target.getCoords()));
		this.setDirection( null);
		this.setTargetPosition( null );
		this.setTarget(null);
		this.stepsToTarget = 0;
	}
	
	public int getSize()
	{
		return this.size;
	}
	
	public void setSize(final int size)
	{
		this.size = size;
	}

	public float getTimeToGo()
	{
		return this.stepsToTarget;
	}
	
	
}

⌨️ 快捷键说明

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