Package org.freerealm.property

Source Code of org.freerealm.property.BuildTileImprovement

package org.freerealm.property;

import java.util.Iterator;
import java.util.Vector;
import org.freerealm.tile.Tile;
import org.freerealm.tile.TileBuildablePrerequisite;
import org.freerealm.tile.improvement.TileImprovementType;

/**
*
* @author Deniz ARIKAN
*/
public class BuildTileImprovement implements Property {

    private static final String NAME = "BuildTileImprovement";
    private int productionPoints;
    private Vector<TileImprovementType> tileImprovements = new Vector<TileImprovementType>();

    public String getName() {
        return NAME;
    }

    public boolean canBuildTileImprovement(TileImprovementType tileImprovement, Tile tile) {
        if (tile.hasImprovement(tileImprovement)) {
            return false;
        }
        if (!getTileImprovements().contains(tileImprovement)) {
            return false;
        }
        if (!tileImprovement.canBeBuiltOnTileType(tile.getType())) {
            return false;
        }
        Iterator<TileBuildablePrerequisite> tileBuildablePrerequisiteIterator = tileImprovement.getPrerequisitesIterator();
        while (tileBuildablePrerequisiteIterator.hasNext()) {
            TileBuildablePrerequisite tileBuildablePrerequisite = tileBuildablePrerequisiteIterator.next();
            tileBuildablePrerequisite.setTile(tile);
            if (!tileBuildablePrerequisite.isSatisfied()) {
                return false;
            }
        }
        return true;
    }

    public Vector<TileImprovementType> getTileImprovements() {
        return tileImprovements;
    }

    public int getProductionPoints() {
        return productionPoints;
    }

    public void setProductionPoints(int productionPoints) {
        this.productionPoints = productionPoints;
    }
}
TOP

Related Classes of org.freerealm.property.BuildTileImprovement

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.