void LateUpdate()
    {
        // record a current selected tower, if no tower is selected at the beginning, _type is null
        if (!_set)
        {
            return;
        }
        int[] info         = new int[11];
        int[] upgratedInfo = new int[11];
        switch (_type)
        {
        case Tower.TowerType.Tank:
            _tankTower.GetTowerInfo(info);
            _tankTower.GetTowerUpgradedInfo(upgratedInfo);
            break;

        case Tower.TowerType.Range:
            _rangeTower.GetTowerInfo(info);
            _rangeTower.GetTowerUpgradedInfo(upgratedInfo);
            break;

        case Tower.TowerType.Slow:
            _slowTower.GetTowerInfo(info);
            _slowTower.GetTowerUpgradedInfo(upgratedInfo);
            break;

        case Tower.TowerType.Heal:
            _healTower.GetTowerInfo(info);
            _healTower.GetTowerUpgradedInfo(upgratedInfo);
            break;

        case Tower.TowerType.Gold:
            _goldTower.GetTowerInfo(info);
            _goldTower.GetTowerUpgradedInfo(upgratedInfo);
            break;
        }
        // dynamically update current tower hp
        UpdateTowerInfo(info, upgratedInfo);
        if (info[3] == info[4])
        {
            _repairButton.SetHpCheckFlag();
        }
        else
        {
            _repairButton.ResetHpCheckFlag();
        }
    }
Exemplo n.º 2
0
    public int CheckTowerInfo(int index, int[] info) // return the tower range, store other info array
    {
        _towerGameObject = Instantiate(Towers[index], new Vector3(), Quaternion.identity) as GameObject;
        switch (index)
        {
        case 0:
            _tankTowerPtr = _towerGameObject.GetComponent <TankTower>();
            _tankTowerPtr.GetTowerInfo(info);
            _tankTowerPtr.Remove();
            break;

        case 1:
            _rangeTowerPtr = _towerGameObject.GetComponent <RangeTower>();
            _rangeTowerPtr.GetTowerInfo(info);
            _rangeTowerPtr.Remove();
            break;

        case 2:
            _slowTowerPtr = _towerGameObject.GetComponent <SlowTower>();
            _slowTowerPtr.GetTowerInfo(info);
            _slowTowerPtr.Remove();
            break;

        case 3:
            _healTowerPtr = _towerGameObject.GetComponent <HealTower>();
            _healTowerPtr.GetTowerInfo(info);
            _healTowerPtr.Remove();
            break;

        case 4:
            _goldTowerPtr = _towerGameObject.GetComponent <GoldTower>();
            _goldTowerPtr.GetTowerInfo(info);
            _goldTowerPtr.Remove();
            break;
            // TODO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        }
        Destroy(_towerGameObject);
        return(info[0]);
    }
    void OnMouseDown()
    {
        _gameBoard.ClearHighlightTiles();
        _towerInfoPanel.ResetTextColor();
        if (_towerExist)
        {
            _sellButton.SellOptButton.interactable = true;
            if (_levelManager.CurrentGamePhase() == GameBoard.GamePhase.BattlePhase)
            {
                _sellButton.SellOptButton.interactable = false;
            }
            _sellButton.setTowerEventHandler(this);
            _upgradeButton.setTowerEventHandler(this);
            _repairButton.setTowerEventHandler(this);
            _yesButton.setTileEventHandler(this);
            _towerOperationPanel.Appear();
            int[] towerInfo         = new int[11];
            int[] upgradedTowerInfo = new int[11];
            // highlight attack range and if there is enough money to upgrade or repair
            if (0 == _currentTowerType)
            {
                DisplayAttackRange(_tankTowerPtr.GetTowerInfo(towerInfo));
                _tankTowerPtr.GetTowerUpgradedInfo(upgradedTowerInfo);
                _towerInfoPanel.SetTankTower(_tankTowerPtr);
                if (_tankTowerPtr.UpgradeCost > _levelManager.GetGold())
                {
                    _upgradeButton.SetGoldCheckFlag(_tankTowerPtr.UpgradeCost);
                }
                if (_tankTowerPtr.IsDestory())
                {
                    _upgradeButton.SetDestroyFlag();
                }
                if (_tankTowerPtr.RepairCost > _levelManager.GetGold())
                {
                    _repairButton.SetGoldCheckFlag();
                }
                if (_tankTowerPtr.IsFullHealth())
                {
                    _repairButton.SetHpCheckFlag();
                }
            }
            if (1 == _currentTowerType)
            {
                DisplayAttackRange(_rangeTowerPtr.GetTowerInfo(towerInfo));
                _rangeTowerPtr.GetTowerUpgradedInfo(upgradedTowerInfo);
                _towerInfoPanel.SetRangeTower(_rangeTowerPtr);
                if (_rangeTowerPtr.UpgradeCost > _levelManager.GetGold())
                {
                    _upgradeButton.SetGoldCheckFlag(_rangeTowerPtr.UpgradeCost);
                }
                if (_rangeTowerPtr.IsDestory())
                {
                    _upgradeButton.SetDestroyFlag();
                }
                if (_rangeTowerPtr.RepairCost > _levelManager.GetGold())
                {
                    _repairButton.SetGoldCheckFlag();
                }
            }
            if (2 == _currentTowerType)
            {
                DisplayAttackRange(_slowTowerPtr.GetTowerInfo(towerInfo));
                _slowTowerPtr.GetTowerUpgradedInfo(upgradedTowerInfo);
                _towerInfoPanel.SetSlowTower(_slowTowerPtr);
                if (_slowTowerPtr.UpgradeCost > _levelManager.GetGold())
                {
                    _upgradeButton.SetGoldCheckFlag(_slowTowerPtr.UpgradeCost);
                }
                if (_slowTowerPtr.IsDestory())
                {
                    _upgradeButton.SetDestroyFlag();
                }
                if (_slowTowerPtr.RepairCost > _levelManager.GetGold())
                {
                    _repairButton.SetGoldCheckFlag();
                }
            }
            if (3 == _currentTowerType)
            {
                DisplayAttackRange(_healTowerPtr.GetTowerInfo(towerInfo));
                _healTowerPtr.GetTowerUpgradedInfo(upgradedTowerInfo);
                _towerInfoPanel.SetHealTower(_healTowerPtr);
                if (_healTowerPtr.UpgradeCost > _levelManager.GetGold())
                {
                    _upgradeButton.SetGoldCheckFlag(_healTowerPtr.UpgradeCost);
                }
                if (_healTowerPtr.IsDestory())
                {
                    _upgradeButton.SetDestroyFlag();
                }
                if (_healTowerPtr.RepairCost > _levelManager.GetGold())
                {
                    _repairButton.SetGoldCheckFlag();
                }
            }
            if (4 == _currentTowerType)
            {
                DisplayAttackRange(_goldTowerPtr.GetTowerInfo(towerInfo));
                _goldTowerPtr.GetTowerUpgradedInfo(upgradedTowerInfo);
                _towerInfoPanel.SetGoldTower(_goldTowerPtr);
                if (_goldTowerPtr.UpgradeCost > _levelManager.GetGold())
                {
                    _upgradeButton.SetGoldCheckFlag(_goldTowerPtr.UpgradeCost);
                }
                if (_goldTowerPtr.IsDestory())
                {
                    _upgradeButton.SetDestroyFlag();
                }
                if (_goldTowerPtr.RepairCost > _levelManager.GetGold())
                {
                    _repairButton.SetGoldCheckFlag();
                }
            }
            _towerInfoPanel.SetTowerInfo(towerInfo);
            _towerInfoPanel.SetUpgradedTowerInfo(upgradedTowerInfo);
            _towerInfoPanel.Appear();
            _towerBuildPanel.DisAppear();
            _buildCheckPanel.DisAppear();
            _notificationPanel.DisAppear();
        }
        else
        {
            _gameBoard.HighlightTileAt(GridX, GridY, new Color(0f, 1f, 0.2f, 0.5f));
            if (GameBoard.GamePhase.BattlePhase == _gameBoard.CurrentGamePhase)
            {
                _gameBoard.ClearHighlightTiles();
                _buildCheckPanel.DisAppear();
                _towerInfoPanel.DisAppear();
                _towerOperationPanel.DisAppear();
                _notificationPanel.DisAppear();
                return;
            }
            _tankTowerButton.setTowerEventHandler(this);
            _rangeTowerButton.setTowerEventHandler(this);
            _slowTowerButton.setTowerEventHandler(this);
            _healTowerButton.setTowerEventHandler(this);
            _goldTowerButton.setTowerEventHandler(this);

            _yesButton.setTileEventHandler(this);
            _towerBuildPanel.Appear();
            _towerOperationPanel.DisAppear();
            _towerInfoPanel.DisAppear();
            _buildCheckPanel.DisAppear();
            _notificationPanel.DisAppear();
        }
    }