public GamePlayScreen(IGameScreenManager screenManager, IGestureManager gm)
            : base(screenManager)
        {
            gameBoard = new PZBoard(9, 4, objectManager);
            gameBoard.Board = new int[,] {
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0}
            };

            this.gm = gm;

            this.playBacground = new PlayBackground(this.Game, SCSServices.Instance.ResourceManager.GetResource<Texture2D>(backgroundNames[GRandom.RandomInt(backgroundNames.Length)]));
            ResetGame(0);
        }
        public GamePlayScreen(IGameScreenManager screenManager, IGestureManager gm, PvZGrowSystem growSys)
            : base(screenManager, "PlayScreen")
        {
            gameBoard = new PZBoard(9, 4, objectManager);
            gameBoard.Board = new int[,] {
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0},
                {0, 0, 0, 0, 0, 0, 0, 0, 0}
            };

            this.gm = gm;
            level = PZLevelManager.Instance.GetLevel();
            level.OnBeginWave += level_OnBeginWave;
            this.playBacground = new PlayBackground(this.Game, SCSServices.Instance.ResourceManager.GetResource<Texture2D>(level.Background));
            this.playBacground.Initialize();
            this.playBacground.OnAnimatingCompleted += this.OnBackgroundAnimatingCompleted;
            this.playBacground.StartAnimate();

            _messageCenter = new MessageCenter(this.Game);

            this.growSystem = growSys;
        }
 public void Update(PZBoard board, GameTime gameTime)
 {
     if (_currentState == LevelState.BEGIN)
     {
         if (_currentTime >= Waves[_currentWave].TimeBeginWave)
         {
             ////Debug.WriteLine("LEVEL: Start Wave " + _currentWave);
             _currentState = LevelState.WAVING;
             _currentTime = TimeSpan.Zero;
         }
         else
             _currentTime += gameTime.ElapsedGameTime;
     }
     else if (_currentState == LevelState.WAVING)
     {
         Wave wave = Waves[_currentWave];
         if (wave.CurrentState == WaveState.WAVING)
         {
             wave.Update(board, gameTime);
         }
         else if (wave.CurrentState == WaveState.END)
         {
             _currentState = LevelState.ENDWAVE;
         }
     }
     else if (_currentState == LevelState.ENDWAVE) // Delay giua cac Wave
     {
             if (_currentTime >= Waves[_currentWave].TimeNextWave)
             {
                 _currentWave++; // Tang wave
                 if (_currentWave >= Waves.Count) // Het wave
                     _currentState = LevelState.END;
                 else
                 {
                     _currentState = LevelState.WAVING;
                     _currentTime = TimeSpan.Zero;
                 }
             }
             else
             {
                 _currentTime += gameTime.ElapsedGameTime;
                 //Debug.WriteLine("LEVEL: Delay Wave ");
             }
     }
     else if (_currentState == LevelState.END)
     {
         //Debug.WriteLine("LEVEL: End LEvel");
     }
 }
        public void Update(PZBoard board, GameTime gameTime)
        {
            if (_numberZombie == 0)
            {
                _numberZombie = rand.Next(NumberFrom, NumberTo);
            }

            if (_currentState == WaveState.WAVING)
            {
                if (_nextZombieTime == TimeSpan.Zero)
                {
                    _nextZombieTime = TimeSpan.FromSeconds(TimeNextZombieFrom + rand.NextDouble() * (TimeNextZombieTo - TimeNextZombieFrom)); // Calc time to drop zombie
                    //Debug.WriteLine("WAVE: Tha ZOMBIE trong {0} giay", _nextZombieTime);
                }

                if (_currentTime >= _nextZombieTime) // Tha zombie
                {

                    string zombieString = Zombies[rand.Next(0, Zombies.Count)];
                    ObjectEntity obj = GameObjectCenter.Instance.CreateObject(zombieString);
                    int row = rand.Next(0, 4);
                    //Debug.WriteLine("LEVEL: Tha ZOMBIE at row {0}", row);
                    board.AddObjectAt(obj, row, 10);
                    _currentTime = TimeSpan.Zero;
                    _nextZombieTime = TimeSpan.Zero;
                    _currentZombie++;
                }
                else
                    _currentTime += gameTime.ElapsedGameTime;

                // Kiem tra da tha het zombie chua
                if (_currentZombie >= _numberZombie)
                    _currentState = WaveState.END;
            }
        }
 public PvZGameGrow(PZBoard gameBoard)
 {
     _gameBoard = gameBoard;
 }