コード例 #1
0
ファイル: EnemyPatterns.cs プロジェクト: shemloft/Game
        public GameState MoveEnemies(
            GameState state,
            Game game,
            int shootingIteration,
            int shootingFrequency,
            bool needToShoot,
            Func <Enemy, ShootingPattern[]> shootingDirection)
        {
            var updatedEnemyHashset = new HashSet <Enemy>();

            foreach (var enemy in state.Enemies)
            {
                enemy.Move();
                if (EnemyKilledPlayer(enemy, state))
                {
                    game.AddDeadEnemy(enemy);
                    state.Enemies.Remove(enemy);
                    state.IsOver = true;
                    return(state);
                }
                var bulletKilledEnemy      = false; // такое название логичнее
                var bulletThatTouchedEnemy = EnemyTouchedPlayerBullet(enemy, state);
                if (bulletThatTouchedEnemy != null)
                {
                    state.PlayerBullets.Remove(bulletThatTouchedEnemy);
                    //game.CurrentGameState.DeadCharacters.Add(Tuple.Create(bulletThatTouchedEnemy.Location, 0));
                    if (enemy is Boss)
                    {
                        var boss = enemy as Boss;
                        boss.HP--;
                        //EnemyFeatures.Boss.HP--;
                        bulletKilledEnemy = boss.HP <= 0;
                        if (boss.HP <= 0)
                        {
                            game.AddDeadEnemy(enemy);
                        }
                    }
                    else
                    {
                        game.AddDeadEnemy(enemy);
                        game.Score += 100;
                        game.TryToAddPower(enemy);
                        bulletKilledEnemy = true;
                    }
                }
                if (!EnemyFeatures.IsBoss() && game.InField(enemy.Location) && !bulletKilledEnemy ||
                    EnemyFeatures.IsBoss() && !bulletKilledEnemy)
                {
                    updatedEnemyHashset.Add(enemy);
                }
                else
                {
                    continue;
                }
                if (!needToShoot || shootingIteration != shootingFrequency)
                {
                    continue;
                }
                foreach (var vector in shootingDirection(enemy))
                {
                    enemy.Shoot(vector);
                }
            }
            state.Enemies = updatedEnemyHashset;
            return(state);
        }