Пример #1
0
        /*
         * ========================================================================================
         * MonsterTurn ---> Calculate the damage dealt to the Hero
         * ========================================================================================
         */
        private void MonsterTurn()
        {
            int damage;
            int compare = CurrentMonster.Strength - Hero.Defense;

            if (Hero.EquippedArmor != null && Hero.EquippedShield != null)
            {
                Armor  armor         = Hero.EquippedArmor;
                Shield shield        = Hero.EquippedShield;
                int    armorDefense  = Random.Next(armor.MinDefense, armor.MaxDefense + 1);
                int    shieldDefense = Random.Next(shield.MinDefense, shield.MaxDefense + 1);
                int    finalDefense  = (shieldDefense + armorDefense) + Hero.Defense;
                compare = CurrentMonster.Strength - finalDefense;
            }
            else if (Hero.EquippedArmor != null)
            {
                Armor armor        = Hero.EquippedArmor;
                int   armorDefense = Random.Next(armor.MinDefense, armor.MaxDefense + 1);
                int   finalDefense = armorDefense + Hero.Defense;
                compare = CurrentMonster.Strength - finalDefense;
            }
            else if (Hero.EquippedShield != null)
            {
                Shield shield        = Hero.EquippedShield;
                int    shieldDefense = Random.Next(shield.MinDefense, shield.MaxDefense + 1);
                int    finalDefense  = shieldDefense + Hero.Defense;
                compare = CurrentMonster.Strength - finalDefense;
            }

            if (compare <= 0)
            {
                damage = 1;
                Hero.TakeDamage(damage);
            }
            else
            {
                damage = compare;
                Hero.TakeDamage(damage);
            }

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"\n{CurrentMonster.Name} does {damage} damage!");
            Console.WriteLine($"{Hero.Name}'s HP: {Hero.CurrentHP}/{Hero.OriginalHP}");
            Console.ResetColor();

            if (Hero.CurrentHP <= 0)
            {
                Lose();
            }
        }