Esempio n. 1
0
        public void Start()
        {
            playerStage = PlayerStage.Level1;

            // Realign the spawnpoint so it's on the terrain
            spawnPoint.transform.position = VectorUtil.sitOnTerrain(spawnPoint);

            AddBuilding(UnitType.CommandCenter, BuildingFactory.CreateBuilding(this, UnitType.CommandCenter, spawnPoint.transform.position, spawnPoint.transform.rotation));

            AddUnit(UnitType.Rover, UnitFactory.CreateUnit(this, UnitType.Rover, VectorUtil.sitOnTerrain(spawnPoint.transform.position + (Vector3.forward * 10) - (Vector3.left * 2))));
            AddUnit(UnitType.Rover, UnitFactory.CreateUnit(this, UnitType.Rover, VectorUtil.sitOnTerrain(spawnPoint.transform.position + (Vector3.forward * 10) + (Vector3.left * 2))));
        }
        public void CreateLabTest()
        {
            Assert.Throws <Exception>(() => BuildingFactory.CreateBuilding(typeof(Lab)));
            LabBuildingRegister visitor = new LabBuildingRegister();

            BuildingFactory.AddFactory(visitor);
            var building = BuildingFactory.CreateBuilding(typeof(Lab));

            Assert.IsType <Lab>(building);
            var lab = building as Lab;

            Assert.False(lab.AbleToFunction);
            Assert.Equal(10, lab.BuildingTime);
            Assert.Equal(0, lab.BuildProgress);
            Assert.Equal(0, lab.CurrentCapacity);
            Assert.Single(lab.UnitTypes);
            Assert.Equal(typeof(Researcher), lab.UnitTypes.Single());
            Assert.Equal(5, lab.MaxCapacity);
        }
        public void CreateFarmTest()
        {
            Assert.Throws <Exception>(() => BuildingFactory.CreateBuilding(typeof(Farm)));
            FarmBuildingRegister visitor = new FarmBuildingRegister();

            BuildingFactory.AddFactory(visitor);
            var building = BuildingFactory.CreateBuilding(typeof(Farm));

            Assert.IsType <Farm>(building);
            var farm = building as Farm;

            Assert.False(farm.AbleToFunction);
            Assert.Equal(7, farm.BuildingTime);
            Assert.Equal(0, farm.BuildProgress);
            Assert.Equal(0, farm.CurrentCapacity);
            Assert.Single(farm.UnitTypes);
            Assert.Equal(typeof(Farmer), farm.UnitTypes.Single());
            Assert.Equal(1, farm.MaxCapacity);
        }
        public void CreateMiningVillageTest()
        {
            Assert.Throws <Exception>(() => BuildingFactory.CreateBuilding(typeof(MiningVillage)));
            MiningVillageBuildingRegister visitor = new MiningVillageBuildingRegister();

            BuildingFactory.AddFactory(visitor);
            var building = BuildingFactory.CreateBuilding(typeof(MiningVillage));

            Assert.IsType <MiningVillage>(building);
            var miningVillage = building as MiningVillage;

            Assert.False(miningVillage.AbleToFunction);
            Assert.Equal(5, miningVillage.BuildingTime);
            Assert.Equal(0, miningVillage.BuildProgress);
            Assert.Equal(0, miningVillage.CurrentCapacity);
            Assert.Single(miningVillage.UnitTypes);
            Assert.Equal(typeof(Gatherer), miningVillage.UnitTypes.Single());
            Assert.Equal(5, miningVillage.MaxCapacity);
        }
        public void CreateForestCampTest()
        {
            Assert.Throws <Exception>(() => BuildingFactory.CreateBuilding(typeof(ForestCamp)));
            ForestCampBuildingRegister visitor = new ForestCampBuildingRegister();

            BuildingFactory.AddFactory(visitor);
            var building = BuildingFactory.CreateBuilding(typeof(ForestCamp));

            Assert.IsType <ForestCamp>(building);
            var forestCamp = building as ForestCamp;

            Assert.False(forestCamp.AbleToFunction);
            Assert.Equal(5, forestCamp.BuildingTime);
            Assert.Equal(0, forestCamp.BuildProgress);
            Assert.Equal(0, forestCamp.CurrentCapacity);
            Assert.Single(forestCamp.UnitTypes);
            Assert.Equal(typeof(Gatherer), forestCamp.UnitTypes.Single());
            Assert.Equal(5, forestCamp.MaxCapacity);
        }
Esempio n. 6
0
        public Building AddBuilding(string buildingID)
        {
            Building newBuilding = null;

            if (String.IsNullOrEmpty(buildingID))
            {
                throw new NullReferenceException("buildingID");
            }
            else if (String.IsNullOrEmpty(BuildingFactory.GetBuildingName(buildingID)))
            {
                throw new ArgumentException(String.Format("Unknown BuildingID: '{0)'.", buildingID));
            }

            if (!this.buildingCounts.ContainsKey(buildingID))
            {
                this.buildingCounts.Add(buildingID, 0);
            }

            if (this.buildingCounts[buildingID] < this.townHall.TownHallLevel.Details[buildingID].MaxAllowed)
            {
                newBuilding = BuildingFactory.CreateBuilding(buildingID);

                newBuilding.IsDraggingChanged += new RoutedEventHandler(this.Building_IsDraggingChanged);
                newBuilding.IsSelectedChanged += new RoutedEventHandler(this.Building_IsSelectedChanged);

                newBuilding.SetBinding(Building.ShowSpawnShieldLayerProperty, this.SpawnShieldLayerBinding);

                DefensiveBuilding newDefensiveBuilding = newBuilding as DefensiveBuilding;
                if (null != newDefensiveBuilding)
                {
                    newDefensiveBuilding.SetBinding(DefensiveBuilding.ShowAttackRangeLayerProperty, this.AttackRangeLayerBinding);
                }

                this.villageLayoutGrid.Children.Add(newBuilding);

                if (null != this.selectedBuilding)
                {
                    int selectedColumn = Grid.GetColumn(this.selectedBuilding);
                    int selectedRow    = Grid.GetRow(this.selectedBuilding);

                    int initialColumn = selectedColumn;
                    int initialRow    = selectedRow;

                    switch (this.lastDirectionKey)
                    {
                    case (Key.Right):
                        initialColumn = (Village.VillageGridSize < selectedColumn + this.selectedBuilding.GridWidth + newBuilding.GridWidth) ? selectedColumn - newBuilding.GridWidth : selectedColumn + this.selectedBuilding.GridWidth;
                        break;

                    case (Key.Left):
                        initialColumn = (0 > selectedColumn - newBuilding.GridWidth) ? selectedColumn + this.selectedBuilding.GridWidth : selectedColumn - newBuilding.GridWidth;
                        break;

                    case (Key.Up):
                        initialRow = (0 > selectedRow - newBuilding.GridHeight) ? selectedRow + this.selectedBuilding.GridHeight : selectedRow - newBuilding.GridHeight;
                        break;

                    case (Key.Down):
                        initialRow = (Village.VillageGridSize < selectedRow + this.selectedBuilding.GridHeight + newBuilding.GridHeight) ? selectedRow - newBuilding.GridHeight : selectedRow + this.selectedBuilding.GridHeight;
                        break;
                    }

                    Grid.SetColumn(newBuilding, initialColumn);
                    Grid.SetRow(newBuilding, initialRow);
                }
                else
                {
                    Grid.SetColumn(newBuilding, newBuilding.GridWidth);
                    Grid.SetRow(newBuilding, newBuilding.GridHeight);
                }

                newBuilding.IsSelected = true;
                this.buildingCounts[buildingID]++;
            }

            this.RefreshVillageDetails();

            return(newBuilding);
        }