필자는 수업 시간에 C#을 배우고 자유 시간에 자신을 가르치려고했습니다.배열의 값에 따라 위치를 표시하는 방법
C#으로 첫 번째 게임을 만들려고합니다. 지금까지 내 코드는 다음과 같습니다
static void Main(string[] args)
{
string aValue;
int Limit = 20;
int[,] MOVEMENT = new int[20,20];
// MOVEMENT
for (int i = 0; i < 20;)
for (int j = 0; j < 20;)
{
Console.WriteLine("Which direction do you wish to move in?");
aValue = Console.ReadLine();
// MOVE NORTH
if (aValue == "North" || aValue == "north")
{
i = i + 1;
if (i >= 20)
{
Console.WriteLine("You cannot move any further in this direction!");
i = 20;
}
}
// MOVE SOUTH
if (aValue == "South" || aValue == "south")
{
i = i - 1;
if (i <= 0)
{
Console.WriteLine("You cannot move any further in this direction!");
i = 0;
}
}
// MOVE EAST
if (aValue == "East" || aValue == "east")
{
j = j + 1;
if (j >= 20)
{
Console.WriteLine("You cannot move any further in this direction!");
j = 20;
}
}
// MOVE WEST
if (aValue == "West" || aValue == "west")
{
j = j - 1;
if (j <= 0)
{
Console.WriteLine("You cannot move any further in this direction!");
j = 0;
}
}
// Display where the character is after each movement and list possible events
// in the area.
Console.WriteLine("You are now at {0},{1}", i, j);
}
Console.ReadLine();
}
지금 게임에서 다른 위치로 배열 corresponde의 각 요소를 만들고 싶어. 예 : 0,0이 집일 수 있습니다. 0,1은 Village 일 수 있습니다. 0,2가 Desert 일 수 있습니다. 1,5가 호수 일 수 있습니다.
각 위치마다 고유 한 설명 및 일부 이벤트 (If 문 등으로 작성)를 원합니다. Im은 코드가 위치를 표시하는 방법을 확신하지 못합니다 (i는 요소의 값이됩니까?). i와 j도 동일합니다. switch 문을 사용하면이 작업을 수행하는 것이 가장 좋겠지 만 시도해 보았습니다. 작동시키지 못했습니다.
도움을 주시면 감사하겠습니다.