コード例 #1
0
        /// <summary>
        /// Creates new structure according to def belonging to factory's faction
        /// </summary>
        /// <param name="def">Definition of structure to be created</param>
        /// <returns>Structure defined by Def belonging to factory's faction</returns>
        public IStructure <IStructureDef> CreateNewBuilding(IStructureDef def)
        {
            IStructure <IStructureDef> buildingController;

            switch (def)
            {
            case ResourceFactoryDef resourceFactoryDef:
                buildingController = new ResourceFactoryController(resourceFactoryDef, faction);
                break;

            case TrainingStructureDef trainingStructureDef:
                TrainingStructureController structureController = new TrainingStructureController(trainingStructureDef, game.Spawner);
                structureController.Faction = faction;

                GameActionFactory gameActionFactory = new GameActionFactory(game);

                foreach (ITrainableDef trainableDef in trainingStructureDef.TrainableDefs)
                {
                    IGameAction gameAction = gameActionFactory.CreateTrainAction(trainableDef, structureController);
                    structureController.GameActions.Add(gameAction);
                }

                buildingController = structureController;

                break;

            default:
                buildingController         = new BuildingController((BuildingDef)def);
                buildingController.Faction = faction;
                break;
            }

            return(buildingController);
        }
コード例 #2
0
        public void Test_ShouldSetResourceType_WhenGivenDef(ResourceType resourceType)
        {
            //    Arrange
            def.ResourceType = resourceType;

            //    Act
            ResourceFactoryController resourceFactory = new ResourceFactoryController(def, faction);

            //    Assert
            Assert.AreEqual(resourceType, resourceFactory.ResourceType);
        }