private void UpdateGravityEntities(GameState gameState)
        {
            // Update existing gravity bullets
            foreach (GravityEntity gravityEntity in gameState.GravityEntities)
            {
                gravityEntity.Duration -= 1;
            }

            gameState.GravityEntities.RemoveAll(x => x.Duration <= 0);

            // Add new gravity bullets
            gameState.GameTanks.ForEach((gameTank) =>
            {
                if (gameTank.Shooting && gameTank.Bullet.GravityDuration > 0)
                {
                    gameState.GravityEntities.Add(new GravityEntity
                    {
                        Duration = gameTank.Bullet.GravityDuration,
                        Size = new Size(1, 1),
                        X = gameTank.ShotTarget.X,
                        Y = gameTank.ShotTarget.Y,
                        Strength = gameTank.Bullet.GravityStrength
                    });
                }
            });
        }
        private void UpdateAllTanks(GameState gameState)
        {
            foreach (var gameTank in gameState.GameTanks)
            {
                var tank = gameTank.Tank;
                try
                {
                    var tankUpdate = tank.Update(gameState);

                    gameTank.TankColor = tankUpdate.TankColor;
                    MoveTank(gameTank, tankUpdate, tank);
                    DoTankAttack(gameTank, tankUpdate, tank);
                    tank.Heat = gameTank.Heat;
                }
                catch (Exception e)
                {
                    //The tank threw an exception. Bad tank!
                }
            }
            var top = gameState.GameTanks[0];
            gameState.GameTanks.RemoveAt(0);
            gameState.GameTanks.Add(top);
        }
        private void SpawnFoes(GameState gameState)
        {
            CheckForNewWave();

            int foesToSpawnLog = _game.FoesToSpawn;

            while (foesToSpawnLog > 0)
            {
                if (_game.GameState.Wave % 5 == 0)
                {
                    _game.FoesToSpawn = 0;

                    AbilityType type = _game.GameState.WaveType;

                    BossMonster m =
                        new BossMonster(foesToSpawnLog *
                                        (int)(_game.MonsterStartHealth * Math.Pow(1.1, gameState.Wave) + 1), type);
                    m.Location = new Location(gameState.Size.Width / 2 - m.Size.Width / 2.0,
                                gameState.Size.Height / 2 - m.Size.Height / 2.0);

                    foesToSpawnLog = 0;
                    gameState.Foes.Add(m);
                }
                else
                {
                    _game.FoesToSpawn--;
                    foesToSpawnLog /= 10;

                    AbilityType type;
                    int rand = new Random().Next(1, 20);

                    if (rand == 1)
                    {
                        type = AbilityType.Healing;
                    }
                    else if (rand == 2)
                    {
                        type = AbilityType.Splitter;
                    }
                    else if (rand == 3)
                    {
                        type = AbilityType.RangedHeat;
                    }
                    else if (rand == 4)
                    {
                        type = AbilityType.Fast;
                    }
                    else if (rand == 5)
                    {
                        type = AbilityType.Kamakaze;
                    }
                    else
                    {
                        type = _game.GameState.WaveType;
                    }

                    Monster m = new Monster((int)(_game.MonsterStartHealth * Math.Pow(1.1, gameState.Wave) + 1), type)
                    {
                        Location = new Location(gameState.Size.Width / 2 - Monster.Width / 2.0,
                            gameState.Size.Height / 2 - Monster.Height / 2.0)
                    };

                    gameState.Foes.Add(m);
                }
            }
        }
        private void UpdateAllMonsters(GameState gameState)
        {
            foreach (var foe in gameState.Foes)
            {
                var monster = (Monster)foe;
                monster.Update(gameState);

                //Thaw out monsters
                monster.Speed = (monster.Speed * 9999 + monster.MaxSpeed) / 10000.0;
            }
        }
        private void KillDeadGoals(GameState gameState)
        {
            var deadGoals = gameState.Goals.Where(goal => goal.Health <= 0);

            gameState.Goals.RemoveAll(goal => deadGoals.Contains(goal));
            _game.MonsterStartHealth = (int)(_game.MonsterStartHealth * Math.Pow(1.25, deadGoals.Count()));

            if (!gameState.Goals.Any())
            {
                gameState.Lost = true;
            }
        }