0

I am writing a program for connect 4 that works very well. Only problem is that in visual studio the method

    public static void Display(char[,] board)
    {
        Console.Clear();
        for (int i = 1; i < 8; i++)
        {
            Console.Write(" " + i);
        }
        Console.WriteLine();
        for (int j = 0; j < 15; j++)
        {
            Console.Write("_");
        }
        Console.WriteLine();
        for (int i = 0; i < 6; i++)
        {
            for (int j = 0; j < 7; j++)
            {
                Console.Write("|" + board[i, j]);
            }
            Console.WriteLine('|');
        }
        for (int j = 0; j < 15; j++)
        {
            Console.Write("¯");
        }
        Console.WriteLine();
    }

prints the last for loop too low. It is inadequate. It should be like that (works in repl) enter image description here

but gets printed like that (in VS) enter image description here

I tried to use ¯ instead of ‾ but it just printed out question marks ??????????

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Algo
  • 178
  • 7
  • 1
    Some characters can't be translated in some editors – T.S. Apr 13 '20 at 03:01
  • Note that that's not in Visual Studio. Visual Studio doesn't actually execute your code. Anyway, 1) ¯ isn't a standard ASCII character, so that's probably why it shows ????. See [this question](https://stackoverflow.com/questions/5750203/how-to-write-unicode-characters-to-the-console). 2) It appears to be a font difference, or since it's HTML, perhaps they are doing something different with the line-by-line vertical alignment. – ProgrammingLlama Apr 13 '20 at 03:01

1 Answers1

2

Why not using the good old Box Drawing characters?

You will have an output like this:

enter image description here

public static void Display(char[,] board)
{
    Console.Clear();

    Console.Write(" ");
    for (int i = 1; i < 8; i++)
    {
        Console.Write(" " + i + "  ");
    }
    Console.WriteLine();

    Console.Write("┌");
    for (int j = 0; j < 6; j++)
    {
        Console.Write("───┬");
    }
    Console.WriteLine("───┐");

    for (int i = 0; i < 6; i++)
    {
        for (int j = 0; j < 7; j++)
        {
            Console.Write("│" + " " + board[i, j] + " ");
        }
        Console.WriteLine("│");

        Console.Write(i < 5 ? "├───┼" : "└───┴");
        for (int j = 0; j < 5; j++)
        {
            Console.Write(i < 5 ? "───┼" : "───┴");
        }
        Console.WriteLine(i < 5 ? "───┤" : "───┘");
    }

    Console.WriteLine();
}
Oguz Ozgul
  • 6,809
  • 1
  • 14
  • 26
  • Those are not ASCII characters (which is why the title of the page you linked does not actually contain the word ASCII - unlike your link description) – sepp2k Apr 13 '20 at 11:00
  • Thank you a lot sire. You are a genius. Can I get some insight on how you have found all of these characters? Where do you look them up when in trouble? – Algo Apr 14 '20 at 00:18
  • @sepp2k fixed the link description – Oguz Ozgul Apr 14 '20 at 06:20
  • @Algo been taught them in college, q basic – Oguz Ozgul Apr 14 '20 at 06:21
  • "Where do you look them up when in trouble?" there is [this pdf document](https://www.unicode.org/charts/PDF/U2500.pdf) in the link which contains the Range: 2500–257F from the unicode standard. And if this answer solved your problem, you can tick the check mark and accept it. – Oguz Ozgul Apr 14 '20 at 06:36