public void weaponPlus()
{
int swordPlus = 0;
int axePlus = 0;
while (true)
{
Console.WriteLine("> 소지중인 아이템: Sword, Axe");
Console.Write("-강화하시려는 무기의 이름을 입력해주세요: ");
WeaponType inputWeapon = (WeaponType)Enum.Parse(typeof(WeaponType), Console.ReadLine());
Console.WriteLine("> 강화확률 Sword:30%, Bow:25%, Axe:20%");
Console.Write("-강화하시려면 '강화'를 입력해주세요: ");
Console.WriteLine();
Random rd = new Random();
var p = rd.Next(1, 100);
switch (inputWeapon)
{
case WeaponType.Sword:
Console.WriteLine("random: " + p);
if (p <= 30)
{
swordPlus++;
Console.WriteLine($"아이템( { inputWeapon }) 강화에 성공했습니다.");
Console.WriteLine($"소지중인 아이템 : { inputWeapon }(+{swordPlus}), Axe");
}
else
{
Console.WriteLine("강화실패");
}
break;
case WeaponType.Axe:
Console.WriteLine("random: " + p);
if (p <= 100)
{
axePlus++;
Console.WriteLine($" { inputWeapon } 강화에 성공했습니다.");
Console.WriteLine($"소지중인 아이템 : { inputWeapon }(+{axePlus}), Axe");
}
else
{
Console.WriteLine("강화실패");
}
break;
default:
Console.WriteLine($"{inputWeapon} 은 없는 아이템입니다.");
break;
}
Console.WriteLine();
}
} //end
Enum 활용 연습 과제지만, 실무에서 이렇게 형 변환하여 사용하는 건지 감이 안온다.
'c# 강의 > 과제' 카테고리의 다른 글
20200413 - 팩토리 시즈모드 (0) | 2020.04.13 |
---|---|
20200410 - 주말 과제 (0) | 2020.04.12 |
20200409 - while,switch(장비 착용,해제,습득,삭제 등 분기처리) (0) | 2020.04.09 |
20200408 - Enum 과제 (0) | 2020.04.08 |
20200408 - 반복문 (0) | 2020.04.08 |