using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _20200407
{
class app
{
public app()
{
heroTest();
}
public void heroTest()
{
double heroAtt = 0;
int monsterMaxHp = 0;
double monsterHp = 0;
int critical = 0;
buldColor();
for (; ; )
{
Console.Write(" - 영웅의 공격력은 몇 입니까?(1-5)? : ");
// 입력 범위 아니면 범위를 벗어 났습니다.
heroAtt = Convert.ToInt32(Console.ReadLine());
if (heroAtt > 0 || heroAtt > 6)
{
break;
}
else
{
redColor();
Console.WriteLine(" ! 범위가 잘못되었습니다.");
buldColor();
}
}
for (; ; )
{
Console.Write(" - 몬스터의 체력은 몇 입니까?( 10 ~ 20 ) : ");
monsterMaxHp = Convert.ToInt32(Console.ReadLine());
if (monsterMaxHp > 9 && monsterMaxHp < 21)
{
monsterHp = monsterMaxHp;
break;
}
else
{
redColor();
Console.WriteLine(" ! 범위가 잘못되었습니다.");
buldColor();
}
}
// 공격
for (; ; )
{
Console.Write(" - 공격을 하시려면 '공격'을 입력하세요. : ");
string checkMsg = Console.ReadLine();
if (checkMsg == "공격")
{
if (monsterHp > 0)
{
var rand = new Random();
critical = rand.Next(1, 99);
// Console.WriteLine($"{critical} ????" );
if (critical > 50)
{
// 크리티컬
double criAtt = heroAtt * 1.5;
monsterHp = monsterHp - heroAtt;
yellowColor();
Console.WriteLine(" - ★ 치명타 발생");
Console.WriteLine($" - 몬스터를 '세게' 공격 했습니다. -{criAtt} ({monsterHp} / {monsterMaxHp} )");
buldColor();
}
else
{
// 일반공격
monsterHp = monsterHp - heroAtt;
Console.WriteLine($" - 몬스터를 공격 했습니다. -{heroAtt} ({monsterHp} / {monsterMaxHp} )");
}
if (monsterHp <= 0)
{
yellowColor();
Console.WriteLine(" - 몬스터가 쓰러졌습니다. ");
buldColor();
break;
}
}
}
else
{
redColor();
Console.WriteLine(" ! 없는 명령어 입니다. ");
buldColor();
}
} // 공격 for
// 아이템 획득
for (; ; )
{
yellowColor();
Console.WriteLine(" - 몬스터가 아이템(장검) 떨어뜨렸습니다.");
buldColor();
Console.Write(" - 아이템 획득하려면 '장검 집어'를 입력 하세요 : ");
string userMsg = Console.ReadLine();
// Contains
// bool result = sysMsg.Contains(userMsg);
// Replace
string checkMsg = userMsg.Replace(" ", "");
bool result1 = checkMsg.Contains("장검");
bool result2 = checkMsg.Contains("집어");
// Console.WriteLine($"[ {checkMsg} ]잘라낸거");
// Console.WriteLine($"result1: {result1} / result2: {result2}");
if (result1 && result2)
{
whiteColor();
Console.WriteLine(" - 장검을 획득했습니다.");
buldColor();
break;
}
else if (!result1)
{
redColor();
Console.WriteLine($" ! '장검' 을 정확하게 입력해주세요. ");
buldColor();
}
else if (!result2)
{
redColor();
Console.WriteLine($" ! '집어' 를 정확하게 입력해주세요. ");
buldColor();
}else if (!result1 && !result2)
{
redColor();
Console.WriteLine($" ! '장검','집어' 를 정확하게 입력해주세요. ");
buldColor();
}
} //for
} // method
public void buldColor()
{
Console.ForegroundColor = ConsoleColor.Blue;
}
public void redColor() {
Console.ForegroundColor = ConsoleColor.Red;
}
public void yellowColor()
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
public void whiteColor()
{
Console.ForegroundColor = ConsoleColor.White;
}
}
}

 

'c# 강의 > 과제' 카테고리의 다른 글

20200408 - 반복문  (0) 2020.04.08
20200407 - while 과제  (0) 2020.04.07
20200406 - for문 별찍기  (0) 2020.04.06
20200403 - for문 과제 1  (0) 2020.04.03
20200402 - 연산자 과제  (0) 2020.04.02

+ Recent posts