그래서 C#을 익히기 위해 콘솔 기반의 텍스트 게임을 만들고 있습니다.하지만 지금은 고집스럽게 생각하고 있습니다.콘솔 키 누르기가 작동하지 않습니까?
이것은 분명한 대답 일지 모르지만 나는 또 다른 한 쌍의 눈이 필요합니다. 나는 여기에 다른 질문들을 점검했고 그들은 나를 돕지 않는 것처럼 보인다. 내 Main()
에서
, 나는 다음과 같은 한 :
int age;
Console.Write("Before entering the unknown, could you please confirm your age? ");
age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("");
if (age < 18)
{
Console.WriteLine("I'm sorry, you'll now be transferred to a non-explicit version.");
Console.WriteLine("\n<Press any key to continue>");
Console.ReadKey();
Console.Write("\nPlease wait...");
for (int t = 5; t >= 0; t--)
{
Console.CursorLeft = 22;
Console.Write("{0:00}" + " seconds remaining", t);
Thread.Sleep(1000);
}
Console.WriteLine("");
Console.WriteLine("\nTo proceed, please press any key...");
Console.ReadLine();
NonExplicit();
}
셀프 설명. 그것은 NonExplicit()
방법을 명중하면, 다음이 호출됩니다
1)가 타격을 입력 할 필요 보인다 무엇
char yes = Console.ReadKey().KeyChar;
string name;
Console.WriteLine("\nYou're awake? It's about time. Not old enough, eh? That sucks. \n\nListen, I really need your help. Would you be interested? Y/N");
Console.ReadKey();
if (yes == 'y' || yes == 'Y')
{
Console.Write("\nYou will?! Wow, That's fantastic. Right then, where shall I start? \nI know! How about telling me your name? ");
name = Console.ReadKey().ToString();
Console.WriteLine("\nAhh yes, now you mention it, I certainly remember you, {0}!", name);
}
else
{
Console.WriteLine("\nYou don't want to help me? Oh, that's unfortunate... ");
}
일이는 'Y'또는 'Y'는 눌렀을 때,이다 위의 것을 등록하십시오.
2) if
& else
WriteLines
을 실행하며, 1과 함께 사용한다고 가정합니다.
'y/Y'를 누르면 정확한 기준을 읽도록 코드를 어떻게 수정할 수 있습니까? 또는 Enter를 눌러 계속 진행할 필요가 없도록하려면 어떻게합니까?
'char yes = Console.ReadKey(). KeyChar;'그리고 나서'WriteLine' 다음에 또 다른'Console.ReadKey();'? 두 번째'ReadKey()'를 대체하기 위해'char yes = Console.ReadKey(). KeyChar;'를 움직여보십시오. –