示例#1
0
 private void InitialiseControllers()
 {
     gameBehaviourCommandController = new GameBehaviourCommandController(playerType);
     resourceController             = new ResourceController(playerType);
     buildPlotController            = new BuildPlotController(playerType);
     armyController    = new ArmyController(playerType);
     gameLogController = new GameLogController(playerType);
 }
    public override bool Execute()
    {
        BuildPlotController buildPlotController = GetBuildPlotController();

        if (buildPlotController.IsDemolishable(buildPlotLocation))
        {
            buildPlotController.Demolish(buildPlotLocation);
        }
        else
        {
            Debug.LogError(string.Format("Can't demolish. There is no building at {0}", buildPlotLocation));
            return(false);
        }

        return(true);
    }
示例#3
0
    public override bool Execute()
    {
        Debug.Log("build command executing");

        // Get required data on building

        BuildPlotController buildPlotController = GetBuildPlotController();

        buildingModel = BuildingModelFactory.Create(buildingType);
        ResourceTransaction transaction = buildingModel.buildCost;

        // Check if constructing the building is possible

        // Building has already been constructed in another plot
        if (buildPlotController.IsBuilt(buildingType))
        {
            Debug.LogError(string.Format("Error: there is already a {0} on another plot.", buildingType));
            GetGameLogController().Log(string.Format("Error: there is already a {0} on another plot.", buildingType));

            //abort
            return(false);
        }

        // Plot isn't empty
        if (!buildPlotController.IsBuildable(buildPlotLocation))
        {
            Debug.LogError(string.Format("Error: there is already a building on {0}", buildPlotLocation));
            GetGameLogController().Log(string.Format("Error: there is already a building on {0}", buildPlotLocation));


            // abort
            return(false);
        }

        // transaction fails
        if (!PayOutTransaction(transaction))
        {
            // abort
            GetGameLogController().Log(string.Format("Error: not enough resources to construct {0}", buildingType));
            return(false);
        }

        // Success -> Build
        buildPlotController.Build(buildPlotLocation, buildingType, buildingModel);

        return(true);
    }
    public AI_GameBehaviourCommand GetBuildingCommand(BuildingModel model)
    {
        BuildPlotController buildPlotController = GetBuildPlotController();

        BuildingType buildingType = model.type;

        foreach (BuildPlotLocation location in Enum.GetValues(typeof(BuildPlotLocation)).Cast <BuildPlotLocation>())
        {
            BuildingType buildingOnPlot = buildPlotController.buildPlotMap.GetBuilding(location);

            if (buildingOnPlot == BuildingType.NONE)
            {
                GameBehaviourCommand    command   = BuildingCommandFactory.CreateConstructBuildingCommand(location, buildingType, PlayerType.AI);
                AI_GameBehaviourCommand aiCommand = new AI_GameBehaviourCommand(command, model.buildCost, model.constructionTime);
                return(aiCommand);
            }
        }

        // No building commmand
        return(null);
    }