예제 #1
0
        private static void ProcessOpponentEffects(Monster monster)
        {
            GameHelper.RemovedExpiredEffectsAsync(monster);

            foreach (IEffect effect in monster.Effects)
            {
                effect.ProcessRound();
            }
        }
예제 #2
0
        private static void ProcessPlayerEffects(Player player)
        {
            GameHelper.RemovedExpiredEffectsAsync(player);

            foreach (IEffect effect in player.Effects.Where(effect => effect.IsEffectExpired is false))
            {
                if (effect is ChangePlayerDamageEffect changePlayerDmgEffect)
                {
                    changePlayerDmgEffect.ProcessChangePlayerDamageRound(player);
                }
                else if (effect is ChangeArmorEffect changeArmorEffect)
                {
                    changeArmorEffect.ProcessChangeArmorRound();
                }
                else
                {
                    effect.ProcessRound();
                }
            }
        }
예제 #3
0
        public static void StartCombat(Player player, Monster monster)
        {
            Console.Clear();

            string fightStartString = $"{player.Name}, you have encountered a {monster.Name}. Time to fight!";

            OutputHelper.Display.StoreUserOutput(
                Settings.FormatSuccessOutputText(),
                Settings.FormatDefaultBackground(),
                fightStartString);

            while (monster.HitPoints > 0 && player.HitPoints > 0 &&
                   player.InCombat && monster.InCombat)
            {
                GameHelper.RemovedExpiredEffectsAsync(player);
                GameHelper.RemovedExpiredEffectsAsync(monster);

                bool isInputValid = false;
                // Get input and check to see if input is valid, and if not, keep trying to get input from user
                while (!isInputValid)
                {
                    // Show initial output that announces start of fight
                    OutputHelper.ShowUserOutput(player, monster);
                    OutputHelper.Display.ClearUserOutput();
                    // Player will attack, use ability, cast spells, etc. to cause damage
                    _input = InputHelper.GetFormattedInput(Console.ReadLine());
                    Console.Clear();
                    isInputValid = ProcessPlayerInput(player, monster);
                }

                if (player.Effects.Any())
                {
                    ProcessPlayerEffects(player);
                }

                if (_fleeSuccess)
                {
                    return;
                }

                // Check to see if player attack killed monster
                if (monster.HitPoints <= 0)
                {
                    monster.MonsterDeath(player);
                    return;
                }

                if (monster.Effects.Any())
                {
                    ProcessOpponentEffects(monster);
                }

                // Check to see if damage over time effects killed monster
                if (monster.HitPoints <= 0)
                {
                    monster.MonsterDeath(player);
                    return;
                }

                if (monster.IsStunned)
                {
                    continue;
                }

                monster.Attack(player);

                // Check at end of round to see if monster was killed by combat round
                if (monster.HitPoints > 0)
                {
                    continue;
                }

                monster.MonsterDeath(player);

                return;
            }
        }