C#/수업내용
늑대때리기
버스창문
2022. 6. 10. 15:48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study02
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("당신의 이름은 무엇입니까? : ");
string name = Console.ReadLine();
Console.Write("당신의 공격력은 몇입니까?(1 ~ 5)");
string input = Console.ReadLine();
int att = Convert.ToInt32(input);
if (att >= 1 && att <= 5)
{
Console.WriteLine("\n-----------------\n이름 : {0}\n공격력 : {1}\n------------------", name, att);
int wolfMaxHp = 5;
int wolfHp = wolfMaxHp;
Console.WriteLine("\n늑대 출현 ({0}/{1})", wolfHp, wolfMaxHp);
Console.Write("공격하려면 \"공격\"을 입력하세요.");
input = Console.ReadLine();
if (input == "공격")
{
Console.WriteLine("늑대가 피해를 (-{0}) 받았습니다", att);
wolfHp -= att;
if (wolfHp <= 0)
{
Console.WriteLine("늑대가 죽었습니다.");
}
else
{
Console.WriteLine("늑대({0}/{1})가 황급히 도망갑니다.", wolfHp, wolfMaxHp);
}
}
else
{
Console.WriteLine("잘못된 입력입니다.");
}
}
else
{
Console.WriteLine("공격력을 잘못 입력했습니다.");
}
}
}
}
