示例#1
0
        /// <summary>
        /// According to parameter name that shows information of building in the view
        /// And set buttons and images components.
        /// </summary>
        /// <param name="building"></param>
        public void ShowInfoClickedObject(IScrollBuildingModel building)
        {
            _informationView.BuildingImage.enabled = true;

            _informationView.BuildingNameText.enabled = true;
            _informationView.BuildingNameText.text    = building.Name + building.BuildingNumber;

            // Comparison parameter building name with the static building names.
            if (building.Name == Config.BarrackName)
            {
                _informationView.BuildingImage.color = Color.blue;

                _informationView.SoldierCreateButton.enabled      = true;
                _informationView.SoldierCreateButton.interactable = true;
                _informationView.SoldierCreateButton.GetComponent <Image>().enabled          = true;
                _informationView.SoldierCreateButton.GetComponentInChildren <Text>().enabled = true;
            }
            else if (building.Name == Config.PowerPlantName)
            {
                _informationView.BuildingImage.color = Color.yellow;

                if (_informationView.SoldierCreateButton.enabled)
                {
                    _informationView.SoldierCreateButton.enabled      = false;
                    _informationView.SoldierCreateButton.interactable = false;
                    _informationView.SoldierCreateButton.GetComponent <Image>().enabled          = false;
                    _informationView.SoldierCreateButton.GetComponentInChildren <Text>().enabled = false;
                }
            }
            _currentBuildingOnInfo = building;
        }
示例#2
0
        private void AddBuildingToLists(BuildingEventTypes buildingDragEventType)
        {
            BuildingFactory      factory     = new ScrollBuildingModelFactory();
            IScrollBuildingModel newBuilding = null;

            newBuilding = factory.CreateScrollBuildingModel(buildingDragEventType);
            if (_activeCellPositionX != null)
            {
                newBuilding.XIndex = (int)_activeCellPositionX;
            }
            if (_activeCellPositionY != null)
            {
                newBuilding.YIndex = (int)_activeCellPositionY;
            }
            newBuilding.BuildingNumber = _buildingsList[buildingDragEventType].Count + 1;
            _buildingsList[buildingDragEventType].Add(newBuilding);
        }
示例#3
0
        // Finds suitable place for soldiers.
        // when soldier is created, it starts mid-down position of barrack and surround the barracks.
        public void FindSuitableSoldierPosition(IScrollBuildingModel selectedBuilding)
        {
            int currentYIndex = selectedBuilding.YIndex;
            int currentXIndex = selectedBuilding.XIndex + 2;

            for (; currentYIndex >= selectedBuilding.YIndex - 1; currentYIndex--)
            {
                if (currentXIndex <= Config.VerticalGridNumber - 1)
                {
                    if (_gridCellCellArray[currentXIndex, currentYIndex].GridCellType == GridCellTypes.Empty)
                    {
                        CreateSoldierOnMap(currentXIndex, currentYIndex);
                        return;
                    }
                }
            }

            if (currentYIndex >= 0)
            {
                for (; currentXIndex >= selectedBuilding.XIndex - 1; currentXIndex--)
                {
                    if (currentXIndex >= 0 && currentXIndex < Config.VerticalGridNumber)
                    {
                        if (_gridCellCellArray[currentXIndex, currentYIndex].GridCellType == GridCellTypes.Empty)
                        {
                            CreateSoldierOnMap(currentXIndex, currentYIndex);
                            return;
                        }
                    }
                }
            }

            currentXIndex = selectedBuilding.XIndex - 2;
            currentYIndex = selectedBuilding.YIndex - 2;
            if (currentYIndex < 0)
            {
                currentYIndex = currentYIndex + 1;
            }
            if (currentXIndex >= 0 && currentYIndex >= 0)
            {
                for (; currentYIndex <= selectedBuilding.YIndex + 1; currentYIndex++)
                {
                    if (currentYIndex < Config.HorizontalGridNumber)
                    {
                        if (_gridCellCellArray[currentXIndex, currentYIndex].GridCellType == GridCellTypes.Empty)
                        {
                            CreateSoldierOnMap(currentXIndex, currentYIndex);
                            return;
                        }
                    }
                }
            }

            currentXIndex = selectedBuilding.XIndex - 2;
            currentYIndex = selectedBuilding.YIndex + 2;

            if (currentXIndex < 0)
            {
                currentXIndex = 0;
            }
            if (currentXIndex >= 0 && currentYIndex < Config.HorizontalGridNumber)
            {
                for (; currentXIndex < selectedBuilding.XIndex + 2; currentXIndex++)
                {
                    if (_gridCellCellArray[currentXIndex, currentYIndex].GridCellType == GridCellTypes.Empty)
                    {
                        CreateSoldierOnMap(currentXIndex, currentYIndex);
                        return;
                    }
                }
            }

            currentXIndex = selectedBuilding.XIndex + 2;
            currentYIndex = selectedBuilding.YIndex + 2;

            if (currentYIndex >= Config.HorizontalGridNumber)
            {
                currentYIndex = currentYIndex - 1;
            }
            if (currentXIndex < Config.VerticalGridNumber && currentYIndex < Config.HorizontalGridNumber)
            {
                for (; currentYIndex > selectedBuilding.YIndex; currentYIndex--)
                {
                    if (_gridCellCellArray[currentXIndex, currentYIndex].GridCellType == GridCellTypes.Empty)
                    {
                        CreateSoldierOnMap(currentXIndex, currentYIndex);
                        return;
                    }
                }
            }
        }