Beispiel #1
0
 // Use this for initialization
 void Start()
 {
     rTower = Tower.GetComponent <RangedTower>();
 }
Beispiel #2
0
        public static Tower BuyTower(TowerType type)
        {
            Console.WriteLine("Buy Tower called");
            Tower tower = null;

            if (!Tower.PlacingTower)
            {
                switch (type)
                {
                    case TowerType.MeleeTower:
                                            tower = new MeleeTower();
                                            tower.Type = TowerType.MeleeTower;
                                            break;
                    case TowerType.RangedTower:
                                            tower = new RangedTower();
                                            tower.Type = TowerType.RangedTower;
                                            break;
                    case TowerType.SlowTower:
                                            tower = new SlowTower();
                                            tower.Type = TowerType.SlowTower;
                                            break;
                }

                int gold = Player.Gold,
                    cost = tower.Cost;

                if (gold >= cost)
                {
                    tower.Width = (float)tower.Texture.Width;
                    tower.Height = (float)tower.Texture.Height;

                    TowersList.Add(tower);
                    tower.TowerState = TowerState.Placing;
                    Tower.PlacingTower = true;

                    //Console.WriteLine("Player buying tower of type: " + type.ToString());
                }
                else
                {
                    Console.WriteLine("Error: Player cannot afford to buy this tower");
                    tower = null;
                }
            }
            else
            {
                Console.WriteLine("Error: Already placing tower");
                tower = null;
            }

            return tower;
        }