내 아이디어는 텍스트 기반 어드벤처 게임을 만드는 것입니다.... 형식입니다 만 변수처럼 사용됩니다
클래스를 주 수업에서 사용하려고합니다. 'MyAdventure.Window'
는 '유형'하지만 내가하는 방법에 대한 확실하지 해요 '변수'
처럼 사용됩니다 I가 시도하고 있지만, 그것은 나에게 오류를 제공 이것을 해결하십시오. 클래스의 새 인스턴스를 만들려고했지만 작동하지 않는 것 같습니다. 나는 이것에 상당히 새롭다, 그러나 누군가는 도울 수 있었다?
미리 감사드립니다. 여기
내 메인 클래스 (Program.cs)에 대한 코드입니다 :using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyAdventure
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("You cannot feel your body. You don't know where you are.\nThe room you're in is dark. You cannot see much.");
Console.WriteLine("You decide to stand up, and take a look around. You see a door and a window.\nWhich do you check out first?");
Console.WriteLine("A. Window\nB. Door");
string userInput = Console.ReadLine();
//Window theWindow = new Window();
if (userInput.StartsWith("A", StringComparison.CurrentCultureIgnoreCase))
{
Window();
}
else if (userInput.StartsWith("B", StringComparison.CurrentCultureIgnoreCase))
{
Console.WriteLine("You chose the door.");
}
Console.ReadKey();
}
}
}
그리고 이것은 다른 클래스 Window.cs에 대한 코드 (지금까지)입니다 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyAdventure
{
public class Window
{
static void theWindow()
{
Console.WriteLine("You approach the window.");
Console.ReadKey();
}
}
}
당신이 원하는을'Window.theWindow()'제거해야합니다. – CodesInChaos
또한 공용으로 만듭니다. public static void theWindow() – alfoks
코드와 데이터를 구분할 수도 있지만 다른 교훈이라고 생각합니다. – neeKo