2016-12-13 1 views
-3

XCoordinate, YCoordinate 및 그리드를 호출하여 주 디스플레이에 표시하려고합니다. 어떻게해야합니까?이 두 서브 루틴의 값을 어떻게 출력합니까?

public static void DisplayBoard(char[,] Board) 
    { 
     string[,] grid = new string[3, 3] {{" "," "," "}, 
              {" "," "," "}, 
              {" "," "," "}}; 

     string board = System.IO.File.ReadAllText("H:\\BoardGame.txt"); 
     Console.WriteLine(grid);   
    } 


    public static void GetMoveCoordinates(ref int XCoordinate, ref int YCoordinate) 
    { 
     int CommaLocation; 
     bool GameHasBeenWon = false; 
     string CoordinatesInput; 
     string XChar, YChar; 
     while (GameHasBeenWon == false) 
     { 
      try 
      { 
       Console.Write("Enter your coordinates: (x,y) "); 
       CoordinatesInput = Console.ReadLine(); 
       CommaLocation = CoordinatesInput.IndexOf(",".ToString()); 
       XChar = CoordinatesInput.Substring(CommaLocation - 1); 
       YChar = CoordinatesInput.Substring(CommaLocation + 1); 
       XCoordinate = int.Parse(XChar); 
       YCoordinate = int.Parse(YChar); 
      } 
      catch 
      { 
       Console.WriteLine("Invalid Input- Please Try Again"); 
      } 
     } 
    } 
} 
+0

가능한 복제 (HTTP : // 유래 .com/questions/24094093/how-to-print-2d-array-to-console-in-c-sharp) –

답변

0

당신은 다음과 같이 호출 : 잘

int x = 0; 
int y = 0; 
GetMoveCoordinates(ref x, ref y) 
Console.WriteLine("Move was {0},{1}",x,y) 
0

...

string[,] grid = new string[3, 3] {{" "," "," "}, 
             {" "," "," "}, 
             {" "," "," "}}; 

public void AddMove(int x, int y, string p) 
{ 
    grid(x,y) = $" {p} "; 
    Console.SetCursorPosition(0,0) 
    for(int i=0;i<3;i++) 
    { 
     for(int j=0;j<3;j++) 
     { 
      Console.Write(grid(i,j)); 
     } 
     Console.Write("\n"); 
    } 

} 
[C#으로 콘솔에 2 차원 배열을 인쇄하는 방법]의
관련 문제