ljw4104 2021. 3. 17. 18:21

1.

using System;

namespace Study07
{
    enum eWeaponSpeed
    {
        FAST = 4,
        MEDIUM,
        SLOW
    }
    public abstract class Weapon
    {
        protected float weaponConstant;
        protected int speed;
        protected int weaponDamage;
        protected string weaponName;

        public abstract void Attack();
    }
}
using System;

namespace Study07
{
    public class Sword : Weapon
    {
        public Sword(string weaponName, int weaponDamage)
        {
            this.weaponConstant = 1.34f;
            this.weaponName = weaponName;
            this.speed = 6;         //6 : 보통
            this.weaponDamage = (int)(this.weaponConstant * (float)weaponDamage);
        }

        public override void Attack()
        {
            Console.WriteLine("{0}이(가) {1}의 속도로 {2} 데미지로 공격", this.weaponName, (eWeaponSpeed)this.speed, this.weaponDamage);
        }
    }
}
using System;

namespace Study07
{
    public class Spear : Weapon
    {
        public Spear(string weaponName, int weaponDamage)
        {
            this.weaponConstant = 1.49f;
            this.weaponName = weaponName;
            this.speed = 6;
            this.weaponDamage = (int)(weaponConstant * (float)weaponDamage);
        }

        public override void Attack()
        {
            Console.WriteLine("{0}이(가) {1}의 속도로 {2} 데미지로 공격", this.weaponName, (eWeaponSpeed)this.speed, this.weaponDamage);
        }
    }
}
using System;

namespace Study07
{
    public class Dagger : Weapon, Blade
    {
        public Dagger(string weaponName, int weaponDamage)
        {
            this.weaponConstant = 1.30f;
            this.weaponDamage = (int)(weaponConstant * (float)weaponDamage);
            this.weaponName = weaponName;
            this.speed = 4;
        }

        public override void Attack()
        {
            Console.WriteLine("{0}이(가) {1}의 속도로 {2} 데미지로 공격", this.weaponName, (eWeaponSpeed)this.speed, this.weaponDamage);
            AttackAdditional();
        }

        public void AttackAdditional()
        {
            Console.WriteLine("블레이드가 {0}만큼 공격함.", weaponDamage * 1.3f);
        }
    }
}
using System;

namespace Study07
{
    interface Blade
    {
        void AttackAdditional();
    }
}