Пример #1
0
        public void PlaceTower(string towerName, Point curPos)
        {
            foreach (var towerPrefab in _towerViewPrefabs)
            {
                if (towerPrefab.name == towerName)
                {
                    ITowerAI ai   = null;
                    var      data = _towerDatas[towerName];
                    int      cost = data["levels"][0]["cost"];
                    if (TryChangeMoney(-cost))
                    {
                        switch (data["ai"].String)
                        {
                        case "single_shot": ai = new SingleShotAI(data["levels"]); break;

                        case "multi_shot": ai = new MultiShotAI(data["levels"]); break;

                        case "laser_shot": ai = new LaserShotAI(data["levels"]); break;

                        case "rocket_shot": ai = new RocketShotAI(data["levels"], () => Map.Units); break;
                        }
                        var tower = new TowerModel(Shell.Bullet, ai, 1f);
                        Map.AddTower(tower, curPos);

                        var towerView = Instantiate(towerPrefab, _towersRoot);
                        towerView.AttachTo(tower);
                        _towerViews.Add(tower, towerView);

                        _mapView.RegenerateChunk((Vector2)curPos / GraphicsManager.ChunkSize - Vector2.one / 1.99f);
                    }
                    break;
                }
            }
        }
Пример #2
0
 public void AddTower(TowerModel tower, Point position)
 {
     _towers.Add(tower);
     tower.Initialize(this, position);
     this[position].Tower = tower;
     tower.BulletShoot   += Tower_BulletShoot;
 }
Пример #3
0
 public void RemoveTower(TowerModel tower)
 {
     _towers.Remove(tower);
 }