public void UpgradeTower(int serialId)
        {
            if (!dicTower.ContainsKey(serialId))
            {
                Log.Error("Can not find tower serialId '{0}'.", serialId);
                return;
            }

            Tower tower = dicTower[serialId];

            if (tower.Level >= tower.MaxLevel)
            {
                Log.Error("Tower (id:'{0}') has reached the highest level", serialId);
                return;
            }

            DataPlayer dataPlayer = GameEntry.Data.GetData <DataPlayer>();
            int        needEnergy = tower.GetBuildEnergy(tower.Level + 1);

            if (dataPlayer.Energy < needEnergy)
            {
                Log.Error("Energy lack,need {0},current is {1}", needEnergy, dataPlayer.Energy);
                return;
            }

            dataPlayer.AddEnergy(-needEnergy);

            int lastLevel = tower.Level;

            tower.Upgrade();
            GameEntry.Event.Fire(this, UpgradeTowerEventArgs.Create(tower, lastLevel));
        }
        public void SellTower(int serialId)
        {
            if (!dicTower.ContainsKey(serialId))
            {
                Log.Error("Can not find tower serialId '{0}'.", serialId);
                return;
            }

            DataLevel dataLevel = GameEntry.Data.GetData <DataLevel>();

            if (dataLevel.LevelState != EnumLevelState.Prepare && dataLevel.LevelState != EnumLevelState.Normal)
            {
                return;
            }

            Tower tower = dicTower[serialId];

            GameEntry.Event.Fire(this, HideTowerInLevelEventArgs.Create(tower.SerialId));

            DataPlayer dataPlayer = GameEntry.Data.GetData <DataPlayer>();

            if (dataLevel.LevelState == EnumLevelState.Prepare)
            {
                dataPlayer.AddEnergy(tower.TotalCostEnergy);
            }
            else if (dataLevel.LevelState == EnumLevelState.Normal)
            {
                dataPlayer.AddEnergy(tower.SellEnergy);
            }
        }
Exemple #3
0
        public void GameSuccess()
        {
            if (LevelState == EnumLevelState.Gameover)
            {
                return;
            }

            if (CurrentLevelIndex == NONE_LEVEL_INDEX)
            {
                Log.Error("Gameover Only heppen in level");
                return;
            }

            if (LevelState != EnumLevelState.Normal)
            {
                Log.Error("Gameover Only heppen when level is in Normal State,now is {0}", LevelState.ToString());
                return;
            }

            DataPlayer dataPlayer = GameEntry.Data.GetData <DataPlayer>();
            int        hp         = dataPlayer.HP;
            int        starCount  = 0;

            for (int i = 0; i < starScore.Length; i++)
            {
                if (hp >= starScore[i])
                {
                    starCount = i + 1;
                }
                else
                {
                    starCount = i;
                    break;
                }
            }

            SetLevelRecord(CurrentLevelIndex, starCount);
            ChangeLevelState(EnumLevelState.Gameover);
            GameEntry.Event.Fire(this, GameoverEventArgs.Create(EnumGameOverType.Success, starCount));
        }