Example #1
0
 public GameState(Camera camera, int gridSize, ContentManager content)
 {
     mGridSize            = gridSize;
     mCamera              = camera;
     UnitsByPlayer        = new Dictionary <Players, List <IUnit> >();
     SpatialUnitsByPlayer = new SpatialStructuredUnits(mGridSize);
     BuildingsByPlayer    = new Dictionary <Players, List <IUnit> >();
     HeroesByPlayer       = new Dictionary <Players, Hero>();
     UnitsByModel         = new Dictionary <ModelManager.Model, List <IUnit> >();
     Resources            = new Dictionary <Players, Dictionary <Resources, int> >();
     VillagePos           = new Dictionary <Players, Vector2>();
     VillagesByPlayer     = new Dictionary <Players, Village>();
     mMap               = new TileStates[0, 0];
     mPathZones         = new PathFindingZones(0, 0, mGridSize);
     IsPaused           = true;
     mCollision         = new CollisionHandler(gridSize, UnitsByPlayer, IsObstructed);
     mEnemy             = new DummyKi();
     HeroRespawnManager = new HeroRespawnManager();
     mDamageFactor      = new Dictionary <Players, float>();
     foreach (var player in PlayerConstants.sPlayers)
     {
         mDamageFactor.Add(player, 1f);
     }
     mBlockedSound      = new SoundEffectManager(content, "sounds/Logo_miss");
     mStatistics        = new Statistics(content, null, null);
     StatisticsByPlayer = new Dictionary <Players, Dictionary <string, int> >();
     InitStatisticsByPlayer(Players.Player);
     InitStatisticsByPlayer(Players.Ai);
     mPathFinderInstances = new ThreadLocal <PathFinder>(() => new PathFinder(IsObstructed, gridSize));
     mContent             = content;
 }
Example #2
0
        public bool Update(GameTime time)
        {
            if (IsPaused)
            {
                mLastTimeResources = time.TotalGameTime.TotalMilliseconds - (time.TotalGameTime.TotalMilliseconds - mLastTimeResources);
                foreach (var player in BuildingsByPlayer.Keys)
                {
                    foreach (var unit in BuildingsByPlayer[player])
                    {
                        if (unit.UnitType == UnitTypes.Quarry || unit.UnitType == UnitTypes.GoldMine)
                        {
                            unit.IsPaused(time);
                        }
                    }
                }
                return(false);
            }

            if (mLastTimeResources + 5000 < time.TotalGameTime.TotalMilliseconds)
            {
                foreach (var player in Resources.Keys)
                {
                    Resources[player][Unit.Resources.Gold]++;
                    Resources[player][Unit.Resources.Stone]++;
                }

                mLastTimeResources = time.TotalGameTime.TotalMilliseconds;
            }

            AddQueuedUnits();

            SpatialUnitsByPlayer.Update(UnitsByPlayer);

            TriggerAutoDefense(time);

            RunUnitLifecycle(time);


            if (CheckVictory())
            {
                return(true);
            }
            HeroRespawnManager.Update();
            mEnemy.Update(time);

            InGameTime(time);
            InGameStatistics();
            return(false);
        }