-3

I'm trying to call on the XCoordinate and YCoordinate and the grid to display it in the main, how would I go about it?

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");
            }
        }
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Pavvel
  • 23
  • 2
  • 7
  • Possible duplicate of [How to print 2D array to console in C#](http://stackoverflow.com/questions/24094093/how-to-print-2d-array-to-console-in-c-sharp) – Mong Zhu Dec 13 '16 at 10:29

2 Answers2

0

You call it like this:

int x = 0;
int y = 0;
GetMoveCoordinates(ref x, ref y)
Console.WriteLine("Move was {0},{1}",x,y)
Jamiec
  • 133,658
  • 13
  • 134
  • 193
0

well...

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");
    }

}
Ewan
  • 1,261
  • 1
  • 14
  • 25