Пример #1
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]);
    }
 public void SetGoldTower(GoldTower tower)
 {
     _type      = Tower.TowerType.Gold;
     _goldTower = tower;
     _set       = true;
 }
    void Update()
    {
        // disappear all panels when fousing to enter a batte during building OR operation tower phase
        if (!_clearBeforeBattle && _levelManager.CurrentGamePhase() == GameBoard.GamePhase.BattlePhase)
        {
            _towerBuildPanel.DisAppear();
            _towerOperationPanel.DisAppear();
            _towerInfoPanel.DisAppear();
            _buildCheckPanel.DisAppear();
            _notificationPanel.DisAppear();
            _gameBoard.ClearHighlightTiles();
            _clearBeforeBattle = true;
            return;
        }
        // make the above code work for the entire game
        if (_levelManager.CurrentGamePhase() == GameBoard.GamePhase.BuildingPhase)
        {
            _clearBeforeBattle = false;
        }
        if (_confirmed)
        {
            switch (TowerOperation)
            {
            case Operation.Nop:
                break;

            case Operation.TankTower:
                // ask tower controller to build(check avaliable gold)
                _towerGameObject = _towerController.BuildTower(this, GridX, GridY, _towerIndex);
                if (null == _towerGameObject)
                {
                    //Debug.Log("TEH: not enough money or blocking the path");
                }
                else
                {
                    _towerExist       = true;
                    _currentTowerType = 0;
                    _tankTowerPtr     = _towerGameObject.GetComponent <TankTower>(); // get scripts
                    _tankTowerPtr.Setup(this);
                    // check if it blocks the last path
                    if (!_gameBoard.BuildTower(_tankTowerPtr))
                    {
                        SellTower(true);
                        _towerExist = false;
                        _notificationPanel.SetNotificationType("Block");
                        _notificationPanel.Appear();
                    }
                    else
                    {
                        _levelManager.UseGold(_tankTowerPtr.BuildCost);
                        _towerController.AddTileEventHandler(this);
                    }
                }
                break;

            case Operation.RangeTower:
                // ask tower controller to build(check avaliable gold)
                _towerGameObject = _towerController.BuildTower(this, GridX, GridY, _towerIndex);
                if (null == _towerGameObject)
                {
                    //Debug.Log("TEH: not enough money or blocking the path");
                }
                else
                {
                    _towerExist       = true;
                    _currentTowerType = 1;
                    _rangeTowerPtr    = _towerGameObject.GetComponent <RangeTower>(); // get scripts
                    _rangeTowerPtr.Setup(this);
                    // check if it blocks the last path
                    if (!_gameBoard.BuildTower(_rangeTowerPtr))
                    {
                        SellTower(true);
                        _towerExist = false;
                        _notificationPanel.SetNotificationType("Block");
                        _notificationPanel.Appear();
                    }
                    else
                    {
                        _levelManager.UseGold(_rangeTowerPtr.BuildCost);
                        _towerController.AddTileEventHandler(this);
                    }
                }
                break;

            case Operation.SlowTower:
                // ask tower controller to build(check avaliable gold)
                _towerGameObject = _towerController.BuildTower(this, GridX, GridY, _towerIndex);
                if (null == _towerGameObject)
                {
                    //Debug.Log("TEH: not enough money or blocking the path");
                }
                else
                {
                    _towerExist       = true;
                    _currentTowerType = 2;
                    _slowTowerPtr     = _towerGameObject.GetComponent <SlowTower>(); // get scripts
                    _slowTowerPtr.Setup(this);
                    // check if it blocks the last path
                    if (!_gameBoard.BuildTower(_slowTowerPtr))
                    {
                        SellTower(true);
                        _towerExist = false;
                        _notificationPanel.SetNotificationType("Block");
                        _notificationPanel.Appear();
                    }
                    else
                    {
                        _levelManager.UseGold(_slowTowerPtr.BuildCost);
                        _towerController.AddTileEventHandler(this);
                    }
                }
                break;

            case Operation.HealTower:
                // ask tower controller to build(check avaliable gold)
                _towerGameObject = _towerController.BuildTower(this, GridX, GridY, _towerIndex);
                if (null == _towerGameObject)
                {
                    //Debug.Log("TEH: not enough money or blocking the path");
                }
                else
                {
                    _towerExist       = true;
                    _currentTowerType = 3;
                    _healTowerPtr     = _towerGameObject.GetComponent <HealTower>(); // get scripts
                    _healTowerPtr.Setup(this);
                    // check if it blocks the last path
                    if (!_gameBoard.BuildTower(_healTowerPtr))
                    {
                        SellTower(true);
                        _towerExist = false;
                        //_notificationPanel.DisAppear();
                        _notificationPanel.SetNotificationType("Block");
                        _notificationPanel.Appear();
                    }
                    else
                    {
                        _levelManager.UseGold(_healTowerPtr.BuildCost);
                        _towerController.AddTileEventHandler(this);
                        _towerController.AddHealTileEventHandler(this);
                    }
                }
                break;

            case Operation.GoldTower:
                // ask tower controller to build(check avaliable gold)
                _towerGameObject = _towerController.BuildTower(this, GridX, GridY, _towerIndex);
                if (null == _towerGameObject)
                {
                    //Debug.Log("TEH: not enough money or blocking the path");
                }
                else
                {
                    _towerExist       = true;
                    _currentTowerType = 4;
                    _goldTowerPtr     = _towerGameObject.GetComponent <GoldTower>(); // get scripts
                    _goldTowerPtr.Setup(this);
                    // check if it blocks the last path
                    if (!_gameBoard.BuildTower(_goldTowerPtr))
                    {
                        SellTower(true);
                        _towerExist = false;
                        _notificationPanel.SetNotificationType("Block");
                        _notificationPanel.Appear();
                    }
                    else
                    {
                        _levelManager.UseGold(_goldTowerPtr.BuildCost);
                        _towerController.AddTileEventHandler(this);
                    }
                }
                break;

            case Operation.Upgrade:
                if (0 == _currentTowerType)
                {
                    _tankTowerPtr.Upgrade();
                }
                if (1 == _currentTowerType)
                {
                    _rangeTowerPtr.Upgrade();
                }
                if (2 == _currentTowerType)
                {
                    _slowTowerPtr.Upgrade();
                }
                if (3 == _currentTowerType)
                {
                    _healTowerPtr.Upgrade();
                }
                if (4 == _currentTowerType)
                {
                    _goldTowerPtr.Upgrade();
                }
                break;

            case Operation.Repair:
                if (0 == _currentTowerType)
                {
                    if (_tankTowerPtr.RepairCost > _levelManager.GetGold())
                    {
                        _notificationPanel.SetNotificationType("NotEnoughMoney");
                        _notificationPanel.Appear();
                        break;
                    }
                    _tankTowerPtr.Repair();
                }
                if (1 == _currentTowerType)
                {
                    if (_rangeTowerPtr.RepairCost > _levelManager.GetGold())
                    {
                        _notificationPanel.SetNotificationType("NotEnoughMoney");
                        _notificationPanel.Appear();
                        break;
                    }
                    _rangeTowerPtr.Repair();
                }
                if (2 == _currentTowerType)
                {
                    if (_slowTowerPtr.RepairCost > _levelManager.GetGold())
                    {
                        _notificationPanel.SetNotificationType("NotEnoughMoney");
                        _notificationPanel.Appear();
                        break;
                    }
                    _slowTowerPtr.Repair();
                }
                if (3 == _currentTowerType)
                {
                    if (_healTowerPtr.RepairCost > _levelManager.GetGold())
                    {
                        _notificationPanel.SetNotificationType("NotEnoughMoney");
                        _notificationPanel.Appear();
                        break;
                    }
                    _healTowerPtr.Repair();
                }
                if (4 == _currentTowerType)
                {
                    if (_goldTowerPtr.RepairCost > _levelManager.GetGold())
                    {
                        _notificationPanel.SetNotificationType("NotEnoughMoney");
                        _notificationPanel.Appear();
                        break;
                    }
                    _goldTowerPtr.Repair();
                }
                break;

            case Operation.Sell:
                SellTower(false);
                break;
            }
            _confirmed = false;
        }
    }
Пример #4
0
    public GameObject BuildTower(TileEventHandler teh, int x, int y, int index)
    {
        Vector3 gamePosition = _gameBoard.BoardTiles[x, y].TileObject.transform.position;

        _towerGameObject = Instantiate(Towers[index], gamePosition, Quaternion.identity) as GameObject;
        switch (index)
        {
        case 0:
            _tankTowerPtr = _towerGameObject.GetComponent <TankTower>();    // get scripts
            if (_tankTowerPtr.BuildCost > _levelManager.GetGold())
            {
                //Debug.Log("TC: Not enough gold to build");
                _notificationPanel.SetNotificationType("NotEnoughMoney");
                _notificationPanel.Appear();
                Destroy(_towerGameObject);
                return(null);
            }
            break;

        case 1:
            _rangeTowerPtr = _towerGameObject.GetComponent <RangeTower>();    // get scripts
            if (_rangeTowerPtr.BuildCost > _levelManager.GetGold())
            {
                //Debug.Log("TC: Not enough gold to build");
                _notificationPanel.SetNotificationType("NotEnoughMoney");
                _notificationPanel.Appear();
                Destroy(_towerGameObject);
                return(null);
            }
            break;

        case 2:
            _slowTowerPtr = _towerGameObject.GetComponent <SlowTower>();    // get scripts
            if (_slowTowerPtr.BuildCost > _levelManager.GetGold())
            {
                //Debug.Log("TC: Not enough gold to build");
                _notificationPanel.SetNotificationType("NotEnoughMoney");
                _notificationPanel.Appear();
                Destroy(_towerGameObject);
                return(null);
            }
            break;

        case 3:
            _healTowerPtr = _towerGameObject.GetComponent <HealTower>();    // get scripts
            if (_healTowerPtr.BuildCost > _levelManager.GetGold())
            {
                //Debug.Log("TC: Not enough gold to build");
                _notificationPanel.SetNotificationType("NotEnoughMoney");
                _notificationPanel.Appear();
                Destroy(_towerGameObject);
                return(null);
            }
            break;

        case 4:
            _goldTowerPtr = _towerGameObject.GetComponent <GoldTower>();    // get scripts
            if (_goldTowerPtr.BuildCost > _levelManager.GetGold())
            {
                //Debug.Log("TC: Not enough gold to build");
                _notificationPanel.SetNotificationType("NotEnoughMoney");
                _notificationPanel.Appear();
                Destroy(_towerGameObject);
                return(null);
            }
            break;
            // TODO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        }
        //Debug.Log("TC: Tower object created");
        return(_towerGameObject);
    }