Пример #1
0
 // This is a LINQ utility method to get the price of each certian tower type
 public int GetTowerPrice(Tower.TowerType towerType)
 {
     return((from towerCost in TowerCosts
             where towerCost.TowerType
             == towerType
             select towerCost.Cost).FirstOrDefault());
 }
    // when click on an existing tower, store this tower info and display the info
    public void SetTowerInfo(int[] info)
    {
        _repairCase          = false;
        _displayUpgradedInfo = false;
        _towerInfo           = info;
        Tower.TowerType towerType = (Tower.TowerType)info[1];
        switch (towerType)
        {
        case Tower.TowerType.Tank:
            Type.text     = "Tank";
            DpmText.text  = "Atk";
            DpmNum.text   = "" + info[5];
            RTime.text    = "Reload";
            RTimeNum.text = "" + info[6];
            break;

        case Tower.TowerType.Range:
            Type.text     = "Range";
            DpmText.text  = "Atk";
            DpmNum.text   = "" + info[5];
            RTime.text    = "Reload";
            RTimeNum.text = "" + info[6];
            break;

        case Tower.TowerType.Slow:
            Type.text     = "Slow";
            DpmText.text  = "Atk";
            DpmNum.text   = "" + info[5];
            RTime.text    = "Reload";
            RTimeNum.text = "" + info[6];
            break;

        case Tower.TowerType.Heal:
            Type.text     = "Heal";
            DpmText.text  = "Heal";
            DpmNum.text   = "" + info[5];
            RTime.text    = "Reload";
            RTimeNum.text = "" + info[6];
            break;

        case Tower.TowerType.Gold:
            Type.text     = "Gold";
            DpmText.text  = "Gold";
            DpmNum.text   = "" + info[5];
            RTime.text    = "Reload";
            RTimeNum.text = "N/A";
            break;
        }
        Level.text = "" + info[2];
        Hp.text    = info[3] + "\n/" + info[4];
        UCost.text = info[7] + "G";
        RCost.text = info[8] + "G";
        SGain.text = info[9] + "G";
        BCost.text = info[10] + "G";
    }
    public GameObject towerSlotToAddTowerTo;                    // Coordinates to the tower slot

    // take tower type as parameter
    public void AddTower(string towerTypeAsString)
    {
        // Convert enum type to string so that we can use that for event triggers
        Tower.TowerType type = (Tower.TowerType)Enum.Parse(typeof(Tower.TowerType), towerTypeAsString, true);

        // Checks if the player has required Gold or not
        if (TowerManager.Instance.GetTowerPrice(type) <= GameManager.Instance.gold)
        {
            // Subtract the tower price from the total gold
            GameManager.Instance.gold -= TowerManager.Instance.GetTowerPrice(type);

            // call CreateNewTower and disable the AddTowerWindow
            TowerManager.Instance.CreateNewTower(towerSlotToAddTowerTo, type);
            gameObject.SetActive(false);
        }
    }
Пример #4
0
 // The AddTower() method takes a single string parameter: The tower’s type
 public void AddTower(string towerTypeAsString)
 {
     // Convert the string parameter that was passed into the TowerType enum, due to the fact that enums aren't supported for trigger events
     Tower.TowerType type = (Tower.TowerType)Enum.Parse(typeof(Tower.TowerType),
                                                        towerTypeAsString, true);
     // Check that the player has enough gold to afford the chosen tower
     if (TowerManager.Instance.GetTowerPrice(type) <=
         GameManager.Instance.gold)
     {
         // Subtract the tower’s price from the player’s gold
         GameManager.Instance.gold -= TowerManager.Instance.GetTowerPrice(type);
         // Call CreateNewTower() on the TowerManager and disable the AddTowerWindow
         TowerManager.Instance.CreateNewTower(towerSlotToAddTowerTo, type);
         gameObject.SetActive(false);
     }
 }
    // cerate a new cope of the type of tower passed in parameters and also place it on the mentioned slot
    // Also disables the slot so we dont' place two towers in one spot
    public void CreateNewTower(GameObject slotToFill, Tower.TowerType towerType)
    {
        switch (towerType)
        {
        case Tower.TowerType.Stone:
            Instantiate(stoneTowerPrefab, slotToFill.transform.position, Quaternion.identity);
            slotToFill.gameObject.SetActive(false);
            break;

        case Tower.TowerType.Fire:
            Instantiate(fireTowerPrefab, slotToFill.transform.position, Quaternion.identity);
            slotToFill.gameObject.SetActive(false);
            break;

        case Tower.TowerType.Ice:
            Instantiate(iceTowerPrefab, slotToFill.transform.position, Quaternion.identity);
            slotToFill.gameObject.SetActive(false);
            break;
        }
    }
    // when upgrade button is clicked, this function would be called to show updated info
    public void DisplayUpgradedInfo()
    {
        _repairCase          = false;
        _displayUpgradedInfo = true;
        Tower.TowerType towerType = (Tower.TowerType)_upgradeTowerInfo[1];
        switch (towerType)
        {
        case Tower.TowerType.Tank:
            DpmText.text = "Atk";
            DpmNum.text  = "" + _upgradeTowerInfo[5];
            break;

        case Tower.TowerType.Range:
            DpmText.text = "Atk";
            DpmNum.text  = "" + _upgradeTowerInfo[5];
            break;

        case Tower.TowerType.Slow:
            DpmText.text = "Atk";
            DpmNum.text  = "" + _upgradeTowerInfo[5];
            break;

        case Tower.TowerType.Heal:
            DpmText.text = "Heal";
            DpmNum.text  = "" + _upgradeTowerInfo[5];
            break;

        case Tower.TowerType.Gold:
            DpmText.text = "Gold";
            DpmNum.text  = "" + _upgradeTowerInfo[5];
            break;
        }
        Level.text = "" + _upgradeTowerInfo[2];
        //Debug.Log("HP: "+ _upgradeTowerInfo[3]+" "+ _upgradeTowerInfo[4]);
        Hp.text    = _upgradeTowerInfo[3] + "\n/" + _upgradeTowerInfo[4];
        UCost.text = _upgradeTowerInfo[7] + "G";
        RCost.text = _upgradeTowerInfo[8] + "G";
        SGain.text = _upgradeTowerInfo[9] + "G";
    }
    public int GetTowerPriority(Tower.TowerType type)
    {
        switch (type)
        {
        case Tower.TowerType.Tank:
            return(1);

        case Tower.TowerType.Heal:
            return(2);

        case Tower.TowerType.Gold:
            return(0);

        case Tower.TowerType.Range:
            return(3);

        case Tower.TowerType.Slow:
            return(4);

        default:
            return(-1);
        }
    }
    // when repair button and sell button are clicked, this function would be
    // called  in case upgrade button early modify the displayed tower info
    public void SetOriginalowerInfo()
    {
        _displayUpgradedInfo = false;
        Tower.TowerType towerType = (Tower.TowerType)_towerInfo[1];
        switch (towerType)
        {
        case Tower.TowerType.Tank:
            DpmText.text = "Atk";
            DpmNum.text  = "" + _towerInfo[5];
            break;

        case Tower.TowerType.Range:
            DpmText.text = "Atk";
            DpmNum.text  = "" + _towerInfo[5];
            break;

        case Tower.TowerType.Slow:
            DpmText.text = "Atk";
            DpmNum.text  = "" + _towerInfo[5];
            break;

        case Tower.TowerType.Heal:
            DpmText.text = "Heal";
            DpmNum.text  = "" + _towerInfo[5];
            break;

        case Tower.TowerType.Gold:
            DpmText.text = "Gold";
            DpmNum.text  = "" + _towerInfo[5];
            break;
        }
        Level.text = "" + _towerInfo[2];
        Hp.text    = _towerInfo[3] + "\n/" + _towerInfo[4];
        UCost.text = _towerInfo[7] + "G";
        RCost.text = _towerInfo[8] + "G";
        SGain.text = _towerInfo[9] + "G";
    }
 public void SetGoldTower(GoldTower tower)
 {
     _type      = Tower.TowerType.Gold;
     _goldTower = tower;
     _set       = true;
 }
 public void SetHealTower(HealTower tower)
 {
     _type      = Tower.TowerType.Heal;
     _healTower = tower;
     _set       = true;
 }
 public void SetSlowTower(SlowTower tower)
 {
     _type      = Tower.TowerType.Slow;
     _slowTower = tower;
     _set       = true;
 }
 public void SetRangeTower(RangeTower tower)
 {
     _type       = Tower.TowerType.Range;
     _rangeTower = tower;
     _set        = true;
 }
 public void SetTankTower(TankTower tower)
 {
     _type      = Tower.TowerType.Tank;
     _tankTower = tower;
     _set       = true;
 }