Tic-Tac-Toe-PrintBoard

Last modified date

static void PrintBoard()
{
    //  Clear the current console and write a header
    Console.Clear();
    Console.Write("Tic-Tac-Toe");

    //  Loop each cell on the game board, and print the correct value
    for (int i = 0; i < 9; i++)
    {
        //  Check if 'i' is divisible by 3 and if so we need to write a new line
        if ((i % 3) == 0)
            Console.WriteLine();

        //  Print the board
        //  X, O or . for the counter value (. = 0, X = 1, O = 2)
        switch (gameBoard[i])
        {
            case 0:
                Console.Write(".");
                break;
            case 1:
                Console.Write("X");
                break;
            case 2:
                Console.Write("O");
                break;
        }
    }
    //  Adds a new line after printing the board
    Console.WriteLine();
}

nick_h15a4avp