Notice
Recent Posts
Recent Comments
Link
스토리지
과제 8 본문
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();
}
}
'Unity > 수업과제' 카테고리의 다른 글
과제 9 - delegate (0) | 2021.03.22 |
---|---|
과제 - 2048 게임 (0) | 2021.03.20 |
과제 7 (0) | 2021.03.17 |
과제 6 (0) | 2021.03.16 |
과제 5 (0) | 2021.03.14 |
Comments