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

📄 planetdo.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.Planet;
import net.sf.jawp.api.domain.Realm;
import net.sf.jawp.api.domain.SpaceCoords;
import net.sf.jawp.api.domain.stub.PlanetRO;
import net.sf.jawp.gf.api.EntityHolder;
import net.sf.jawp.gf.api.Resolver;
import net.sf.jawp.util.NumUtils;


/**
 * 
 * @author jarek
 * @version $Revision: 1.19 $
 *
 */
public final class PlanetDO extends Planet
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2L;

	private FleetDO homeFleet;
	
	/**
	 *  
	 */
	private float visibleFleet;

	public PlanetDO(final long k, final String name, final RealmDO owner, 
				final int x, final int y, final int z)
	{
		this( k, name, owner, new SpaceCoords(x, y, z));
		
	}
	
	public PlanetDO(final long k, final String name, final RealmDO owner, 
			final SpaceCoords coords)
{
	super(k, name, new EntityHolder<Realm>(owner), coords);
	owner.registerPlanet( this );
	this.visibleFleet = 0;
	
}
	
	public void revealFleetSize(final float step, final NumUtils num)
	{
		final float current = getHomeFleetSize();
		final float diffVal = step * num.getRandom().nextFloat();
		visibleFleet += diffVal * Math.signum(current - visibleFleet);
		if ( visibleFleet < 0)
		{
			this.visibleFleet = 0;
		}
	}
	
	
	public synchronized FleetDO getHomeFleet()
	{
		return this.homeFleet;
	}

	public synchronized void setHomeFleet(final FleetDO homeFleet)
	{
		this.homeFleet = homeFleet;
	}
	
	public int getHomeFleetSize()
	{
		if ( getHomeFleet() != null)
		{
			return this.getHomeFleet().getSize();
		}
		else
		{
			return 0;
		}
	}
	
	public void incFleet( final int nmb, final JAWPGameWorldDO context, final Realm owner)
	{
		if ( getHomeFleet() != null )
		{
			this.getHomeFleet().incFleet(nmb);
		}
		else
		{
			final FleetDO fleet = new FleetDO( context.getUIDGenerator().nextUID(), owner);
			fleet.setSize(nmb);
			fleet.setPosition( new SpaceCoords( getCoords()) );
			this.setHomeFleet(fleet);
			context.registerFleet( fleet );
		}
	}

	public void invade(final FleetDO fleet, final Resolver<RealmDO> realmResolver)
	{
//		TODO: make code more efficient using resolver on DO objects ( )
		realmResolver.find( getOwner().getKey()).removePlanet( this);
		
		this.setHomeFleet( fleet);
		this.setOwner(fleet.getOwner());
		realmResolver.find( fleet.getOwner().getKey()).registerPlanet( this);
		reveal();
		setProduced(0); //production reset
		
	}
	
	public void reveal()
	{
		this.visibleFleet = getHomeFleetSize();
	}

	public Planet getPlayerView(final Realm realm)
	{
		final PlanetRO result = new PlanetRO(this);
		if (this.getOwner().getKey() != realm.getKey())
		{
			result.setHomeFleetSize( Math.round(this.visibleFleet));
			result.setProduced(0);
		}
		return result;
	}
	
	
}

⌨️ 快捷键说明

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